Home > Uncategorized > Control a #Linux machine from C#

Control a #Linux machine from C#


If your architecture involves both Windows and Linux machines, and suddenly Apache crashes, or you otherwise lose contact with the Linux machine, then normally this requires a linux admin to go in, and restart services. But, you can also have your Windows machine remotely monitor these services, and kick them off itself.

  • Ok, this is a contrived situation, it’s more about if you’re a good c# programmer but are clueless around linux – like me.

Anyway, there’s a NuGET package which you can install using Install-Package SSH.NET,  then you can get C# to connect to your Linux server as follows

string strOut = “”;
// Install-Package SSH.NET
using (var client = new SshClient(“”, “root”, “password”))
var result = client.RunCommand(“/etc/init.d/httpd restart”);
strOut = result.Result;


Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: