'C#] How to switch user to su with SSH.Net

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.

cSSH.RunCommand("echo \"" + "admin" + "\" | sudo -S " + "exec \"work.sh\"");
cSSH.RunCommand("echo -e 'admin\n' | sudo -S");
 

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();         
        }

        public void Connect_button(object sender, EventArgs e)
        {

            if (textBox1.Text == "")
                MessageBox.Show("Ip");
            else
            {
                SshClient cSSH = new SshClient(textBox1.Text, 22, "admin", "admin");
                cSSH.Connect();
                if (cSSH.IsConnected)
                {
                    SshCommand test = cSSH.RunCommand("exec \"ifconfig\"");
                    richTextBox1.Text = test.Result + "\r\n";

                    cSSH.RunCommand("echo \"" + "admin" + "\" | sudo -S " + "exec \"/Desktop/work.sh\"");
                    cSSH.RunCommand("echo -e 'admin\n' | sudo -S");
                  
                    cSSH.Disconnect();
                    cSSH.Dispose();
                }
            }
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source