-
-
Notifications
You must be signed in to change notification settings - Fork 910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Able to Connect but Unable to Execute command #1368
Comments
You have to provide more info, versions of server, library and dotnet. How your ssh server is configutated. Can you able to use ssh CLI? |
Can you inspect the value of My guess is that you need to supply an argument to the ping command, and it's telling you that through "standard error" stream and then rudely disconnecting. If |
I am currently using the default server of Welotec's TK525L-v2 router. I am able to connect using ssh on puTTy and run commands on there. I am also able to connect and run commands via command prompt using "ssh user@host". I am using this library (ssh.net) with the target framework being net6.0. I do have a bit of an update. Since yesterday the router was updated to Welotec's TK525L-v2 . Although I am still able to create a client and connect using SshNet I am still not able to successfully run a command. Yesterday, when I tried to run a command the above exception was thrown. Now when I try to run a command, the connection is not aborted or timed out, but I am not able to move forward with the program even after 10 min of trying to execute a command. Because of this reason I am not able to read out command.Error or command.Result. I have tried using ssh commands, commands available in puTTy, as well as non-existent command when running for client.RunCommand("INSERTCOMMANDHERE"); and client.CreateCommand("INSERTCOMMANDHERE"); and regardless I am not able to move forward with the program. Also(fyi) these are the commands available when connected on puTTY or on command prompt: |
This is some dumb, untested code but you could try it for debugging: using (SshCommand command = ...)
{
IAsyncResult result = command.BeginExecute();
Thread.Sleep(5000);
command.OutputStream.Flush();
command.ExtendedOutputStream.Flush();
byte[] readBuffer = new byte[1024];
string stdout = Encoding.UTF8.GetString(readBuffer, 0, command.OutputStream.Read(readBuffer, 0, readBuffer.Length));
string stderr = Encoding.UTF8.GetString(readBuffer, 0, command.ExtendedOutputStream.Read(readBuffer, 0, readBuffer.Length));
_ = command.EndExecute(result);
} If nothing comes of that, perhaps you could fill out this table to help with understanding?
|
I would recommend a shellstream since it seems to require a interactive session and commands in ssh.net are more like plink that PuTTY
|
Thank you guys for your help! It is much appreciated! @Rob-Hague @darkoperator |
Glad you got it working I was unclear, but I was looking for the results of running e.g. As for a "list of commands to try", this would be whatever command can run on the device i.e. the ones you posted earlier, and not something SSH.NET specific. |
Thank you for the clarification. I retried the commands using a cli. I was able to connect and run the commands you sent earlier. There was not a difference between using ssh and ssh -t. With each command, I was prompted to enter a password in the cli and then was able to run commands in the same way I am able to run commands using puTTy. So this makes the issue with running commands using Ssh.NET a bit more confusing. When using the cli to connect and run commands there was mention of server's rsa2(ssh-rsa sha256) key fingerprint before connecting. |
I had the same issue. Also with a router/switch. Had to use:
instead of:
|
@emilycanas was there a root cause / workaround to your issue? |
@LadderLogic as above, the root cause is that the device requires an interactive session (pseudo-termainal) to be allocated, which |
@Rob-Hague thank you. I have access to my linux device configuration, and I would rather change the SSH configuration to not require an interactive session than using the workaround, but I am unable to locate where in my config does it actually enable interactive session. I've posted the sshd config here on SO |
From reading your StackOverflow post it sounds like your problem is that commands are working but taking a long time. This issue is about commands not working at all, so it sounds like a different problem. Perhaps you could start by narrowing down whether the problem occurs only in Posh-SSH, or also when using SSH.NET directly. If the latter, I can only suggest running with a debug build of SSH.NET, and trying to see where things are getting stuck. You can get some logs with https://github.com/sshnet/SSH.NET/wiki/Troubleshooting-SSH.NET#net-tracesource-and-tracelisteners If it does indeed sound like a different problem to this issue, it would be best to open a new one |
I'll attempt a debug build. FWIW, while Posh-SSH times out with default timeout setting, using SSH.NET directly causes it respond 4-8 minutes later, which for the most part I though it was hung and not responding, until I forgot to stop the debug run one of the times and noticed the execution eventually continue :) I was assuming that OP went through similar conclusion since it is not a norm to wait 4-8 minutes for a command to complete. |
Hello!
I am able to connect using SshClient, but I am unable to execute commands. Does anyone know why this might be? The target framework I am using is net6.0. I have tried using different encoding methods, as well as default encoding, but that doesn't seem to make a difference. Does anyone know why this might be and how it can be fixed?
This is the exception that is raised:
Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.
at Renci.SshNet.SshCommand.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.SshCommand.EndExecute(IAsyncResult asyncResult)
at line 26
The text was updated successfully, but these errors were encountered: