Skip to content
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

C# SSH.NET "ERROR: An established connection was aborted by the server" #1028

Open
Christin840512 opened this issue Nov 2, 2022 · 17 comments

Comments

@Christin840512
Copy link

I'm trying to connect to a server thru SSH.NET. It worked fine before but started to show "An established connection was aborted by the server" after some FW update on the server. Below is the code I'm using

private void HandleKeyEvent(object sender, AuthenticationPromptEventArgs e)
        {
            foreach (AuthenticationPrompt prompt in e.Prompts)
            {
                if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    prompt.Response = "password";
                }
            }
        }
private void sshConnectBut_Click(object sender, EventArgs e)
        {
            var auth1 = new PasswordAuthenticationMethod("username", "password");
            var auth2 = new KeyboardInteractiveAuthenticationMethod("username");
            auth2.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent);
            ConnectionInfo conInfo = new ConnectionInfo("Host", 22, "username", auth1, auth2);                
            
            this.sshClient = new SshClient(conInfo);
            this.sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(120);
            
            this.sshClient.Connect();   **<---- Error happened here**
        }

Can anyone help me on this issue please?

@jcalla97
Copy link

jcalla97 commented Nov 4, 2022

I'm experiencing the same issue after a FW update. Where you able to figure out a solution?

@NeoMorfeo
Copy link

NeoMorfeo commented Nov 4, 2022

Can you check the máx connections limits in the server? in my case, this was reached after 3 attemps, and the server close the connection before establishing it, or setting the server identification...

@jcalla97
Copy link

jcalla97 commented Nov 4, 2022

I'm the only one trying to connect to the device. So there are 0 connections when I'm trying to connect. Here is where the error gets thrown:
Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()

@NeoMorfeo
Copy link

can you debug the session and excepcion and check if the server sends you the identificacion?

@jcalla97
Copy link

jcalla97 commented Nov 4, 2022

Would that be stored in my SshClient.ConnectionInfo? Or would that be stored in the exception?

@NeoMorfeo
Copy link

Yes, in the SshClient.ConnectionInfo.

The problem I had face is that connection info is not send by the server, so it cannot be opened.

@jcalla97
Copy link

jcalla97 commented Nov 4, 2022

I don't see a server identification in my ConnectionInfo. This is my ConnectionInfo for my SshClient after the error gets thrown:

image

@NeoMorfeo
Copy link

I was asking for the "server Version" which is shared in the connection phase... so you are not facing the same thing... sorry :(
if you connect using ssh cli using -vvv is there any problem?

@jcalla97
Copy link

jcalla97 commented Nov 4, 2022

No I'm able to connect via ssh on cli and through putty with no issue. I only get the problem when trying to use the library. The cli doesn't have any issues when running with -vvv.

@Christin840512
Copy link
Author

I'm the only one trying to connect to the device. So there are 0 connections when I'm trying to connect. Here is where the error gets thrown: Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server. at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout) at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle) at Renci.SshNet.Session.Connect() at Renci.SshNet.BaseClient.CreateAndConnectSession() at Renci.SshNet.BaseClient.Connect()

I got exactly same error massage as you and still not able to figure it out :(
I have checked all security settings of both two version of FW and there is no difference between them.

@jcalla97
Copy link

jcalla97 commented Nov 7, 2022

So I guess my FW update changed the host key algorithm they use. They originally used rsa-sha2-512/rsa-sha2-256 and updated to use ssh-rsa. But that shouldn't be an issue as to why the connection is getting aborted because this library supports ssh-rsa keys.

@Christin840512
Copy link
Author

Mine is even weird, the host key algorithm keeps the same in the new FW but just can't connect it... Really hope that someone can help on this issue :(

@jcalla97
Copy link

jcalla97 commented Nov 9, 2022

Have you had any updates in the last 2 days? I've been trying to create a new key to test with, but I'm not able to on my server. If you could test this with a new key pair, let me know what the result is.

@jcalla97
Copy link

jcalla97 commented Nov 9, 2022

After doing some more digging, I found that my server updated to OpenSSH version 9.0p1. Can you let me know if you are using the same version of OpenSSH if you are using that for your server?

@jcalla97
Copy link

I have come to the conclusion that my server uses rsa-sha2-256 and rsa-sha512 host key algorithms which is not supported by SSH.Net.

@johnliaoywl
Copy link

I have the same problem. Will SSH.Net support RSA-SHA-256 host key later?

@jcalla97
Copy link

There's this pull request #971 that is a work in progress it looks like, but it hasn't been touched since September so i'm not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants