Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: CreateShell

$
0
0
Hi All,

I need to switch to 'root' through a SSH session so I'm using Oleg's code above to try and run 'sudo su' within the SSH session. I was hoping that creating a shell would allow me to run the command. Alas I keep getting the dreaded 'Error: sudo: sorry, you must have a tty to run sudo'
                var input = new MemoryStream();
                var sw = new StreamWriter(input);
                var output = Console.OpenStandardOutput();
                var shell = client.CreateShell(input, output, output, "xterm", 80, 24, 800, 600, "");
                shell.Stopped += delegate
                {
                    Console.WriteLine("\nDisconnected...");
                };

                shell.Started += delegate
                {
                    sw.AutoFlush = true;

                    //  Start Running Commands
                    var cmd1 = client.RunCommand("sudo su");

                    if (cmd1.Error == null)
                    {
                        Console.WriteLine(cmd1.Result);
                    }
                    else if (cmd1.Error != null)
                    {
                        Console.WriteLine("Error: " + cmd1.Error);
                    }
                    shell.Stop();
                };

//  Start the tty shell
                shell.Start();
I would appreciate some assistance if possible.

I am re-directing the console output to a Text box if that makes a difference???

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>