Unable to connect to SSH server using SSH.NET

I am currently trying to create a control panel program for my Linux server using Visual Basic and SSH.NET. Right now, I want to restart Linux when I click the button.

Here is what I still have:

Dim connInfo As New Renci.SshNet.PasswordConnectionInfo("IP", "USERNAME", "PASSWORD")
Dim sshClient As New Renci.SshNet.SshClient(connInfo)
Dim cmd As Renci.SshNet.SshCommand

Private Sub MaterialFlatButton1_Click(sender As Object, e As EventArgs) Handles MaterialFlatButton1.Click
    Using sshClient
        sshClient.Connect()
        cmd = sshClient.RunCommand("reboot")
        sshClient.Disconnect()
    End Using
End Sub

When I click the button, an error appears:

An unhandled exception of type "Renci.SshNet.Common.SshConnectionException" occurred in Renci.SshNet.dll

Additional Information: The established connection was interrupted by software on your host machine.

Is there anything that I will need to change using my code?

+4
source share
3 answers

. tl; dr: - SSH.NET:

Install-Package SSH.NET -Pre

Linux- :

grep 'sshd' /var/log/auth.log

, :

sshd [2467]: fatal: mm_answer_moduli: : 2048 2048 1024

ssh- , () SSH.NET . , , , 1024. codeplex. , , .

+4

, diffie-hellman-group1-sha1. , , Open SSH .

Linux-

/ .. /SSH/sshd _config

(- )

# Disable all Kex Algorithms but the one defined below (so Renci SSH.NET 2013 works)
KexAlgorithms diffie-hellman-group1-sha1

ssh:

sudo service ssh stop
sudo service ssh start

SSH.NET , ssh () :

( ssh cygwin, )

~/.ssh/

KexAlgorithms +diffie-hellman-group1-sha1

, , , , .

+7

The RunCommand method expects a response from the connected device. Running reboot, shutdown, or shutdown commands will not allow a response from the device and will raise an SshConnectionException.

I wrapped this command in try / catch, as this exception is expected. Here is an example in C #:

try
{
    sshClient.RunCommand("reboot");
}
catch (SshConnectionException exception)
{
    // do something
}
0
source

All Articles