Free and Easy SSH in c#

Filed Under (Code) by Mystalia on 31-05-2008

Tagged Under : , ,

If you’re looking for an easy way to communicate through ssh without paying rediculous prices for components, then read on.

Behold: SharpSSH (Download). It is a free communications component that is great for ssh.

Add the binary dll’s as a reference to your project.
The usage is surprisingly simple.

Tamir.SharpSsh.SshStream ssh = new Tamir.SharpSsh.SshStream(serverip, username, password);

The server ip does not need a port, it uses standard port 22.

string command = “killall -u username”; // could be any command
ssh.Write(command);
ssh.ReadResponse();

and when you are done…

ssh.Close();

To overcome issues with root password prompting you must set the server so that a username does not require a password.