I am currently trying to make a control panel-like program for my Linux server using Visual Basic and SSH.NET. Right now, I want to make the Linux machine reboot when I press a button.
Here is what I have so far:
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 press the button, the error I get is:
An unhandled exception of type 'Renci.SshNet.Common.SshConnectionException' occurred in Renci.SshNet.dll
Additional information: An established connection was aborted by the software in your host machine.
Is there anything I would need to change with my code?
If you are the server administrator, there is the option of limiting the Key Exchange Algorithms to diffie-hellman-group1-sha1. It is important to notice that this algorithm is not considered safe anymore, but Open SSH supports it.
To do that, go to your linux server and edit the file
/etc/ssh/sshd_config
Add the lines (somewhere in the middle of the file)
# Disable all Kex Algorithms but the one defined below (so Renci SSH.NET 2013 works)
KexAlgorithms diffie-hellman-group1-sha1
Restart ssh:
sudo service ssh stop
sudo service ssh start
Now SSH.NET will work, but to connect to the server via ssh (terminal), you should define the protocol on you client config file:
Edit the file (I'm using ssh on cygwin, other clients are beyond my knowledge)
~/.ssh/config
Add the line
KexAlgorithms +diffie-hellman-group1-sha1
Just to conclude, I ended up not using this solution because the latest filezilla does not connects with the server, and I have a user using it to upload files.