title: C#] How to switch user to su with SSH.Net
body: <p>Connect to Ubuntu PC using SSH.Net,
  I want to switch user to root and execute some commands and shell scripts.
  I found few codes like below, but they didn't work.</p>
  <pre><code>cSSH.RunCommand(&quot;echo \&quot;&quot; + &quot;admin&quot; + &quot;\&quot; | sudo -S &quot; + &quot;exec \&quot;work.sh\&quot;&quot;);
  cSSH.RunCommand(&quot;echo -e 'admin\n' | sudo -S&quot;);
   
  
  namespace WindowsFormsApp1
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();         
          }
  
          public void Connect_button(object sender, EventArgs e)
          {
  
              if (textBox1.Text == &quot;&quot;)
                  MessageBox.Show(&quot;Ip&quot;);
              else
              {
                  SshClient cSSH = new SshClient(textBox1.Text, 22, &quot;admin&quot;, &quot;admin&quot;);
                  cSSH.Connect();
                  if (cSSH.IsConnected)
                  {
                      SshCommand test = cSSH.RunCommand(&quot;exec \&quot;ifconfig\&quot;&quot;);
                      richTextBox1.Text = test.Result + &quot;\r\n&quot;;
  
                      cSSH.RunCommand(&quot;echo \&quot;&quot; + &quot;admin&quot; + &quot;\&quot; | sudo -S &quot; + &quot;exec \&quot;/Desktop/work.sh\&quot;&quot;);
                      cSSH.RunCommand(&quot;echo -e 'admin\n' | sudo -S&quot;);
                    
                      cSSH.Disconnect();
                      cSSH.Dispose();
                  }
              }
          }
  </code></pre>