August 8th, 2010, 10:48 AM
SSH commands using C#
I need to be able to restart some programs on a remote linux server using SSH and C#.
Allready got a great library to make my work easier: SharpSSH
This is what the code looks like using the library.
SshStream ssh = new SshStream("192.168.1.50", "user", "password");
Now the command I would like to use is: "sudo /etc/init.d/squid restart"
This command restarts a program called squid and reloads its configurationfiles on an Ubuntu 8.04 LTS server.
The PROBLEM is, entering such a command he asks for the sudo password ( root password ).
I tried to write the two commands after eachother but this won't work :
ssh.Write("sudo /etc/init.d/squid restart");
Any other solutions?
November 28th, 2010, 03:59 AM
Re: SSH commands using C#
Did the issue resolved as I've the same issue while executing following command. This command executes but user did not change. Any idea?
string sudouser_cmd = "echo " + "\"" + password + "\"" + " `sudo -S su - " + sudo_user + "`";
string sudouser_output = ssh.RunCommand(sudouser_cmd);
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.