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

New Post: su command

$
0
0
Hi I can't get it to work either .
can you please help below is my code. Thanks
 public void ServerConnexion()
        {
            try
            {
                KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(this.username);
                PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(this.username, this.password);

                kauth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent);

                this.Server = new SshClient(new ConnectionInfo(this.servername, this.port, this.username, pauth, kauth));

                this.Server.Connect();

                ShellStream shell = this.Server.CreateShellStream("xterm", 80, 24, 800, 600, 1024);

                System.IO.StreamReader reader = new StreamReader(shell);
                System.IO.StreamWriter writer = new StreamWriter(shell);

                writer.AutoFlush = true;

                //writer.Write("su - " + suUsr + "\n");
                shell.Write("su - " + this.suUsr + "\n");

                while (true)
                {
                    var output = reader.ReadLine();

                    if (output.EndsWith("Password: "))
                    {
                        break;
                    }
                }

                //writer.Write(suPass + "\n");
                shell.Write(this.suPass + "\n");

                KeyboardInteractiveAuthenticationMethod kAuth = new KeyboardInteractiveAuthenticationMethod(this.suUsr);
                PasswordAuthenticationMethod pAuth = new PasswordAuthenticationMethod(this.suUsr, this.suPass);

                kAuth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent);
                

            }
            catch (Exception)
            {
                
                throw;
            }

        }

Viewing all articles
Browse latest Browse all 1729

Trending Articles



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