-
August 8th, 2010, 10:48 AM
#1
SSH commands using C#
Hi,
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");
ssh.Write("command");
ssh.Close();
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");
ssh.Write("theSudoPassword");
Any other solutions?
-
November 28th, 2010, 04:59 AM
#2
Re: SSH commands using C#
Hello Dear,
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);
Regards,
Azhar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|