CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Posts
    4

    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?

  2. #2
    Join Date
    Nov 2010
    Posts
    1

    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
  •  





Click Here to Expand Forum to Full Width

Featured