SSH commands using C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: SSH commands using C#

  1. #1
    Join Date
    Aug 2010

    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("", "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?

  2. #2
    Join Date
    Nov 2010

    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);


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center