kmitchellwr has asked for the wisdom of the Perl Monks concerning the following question:

How can I set the proper pty in order to get sudo to work with Net::SSH2 on a remote host? We want to be able to run sudo as a local user on the remote host.

Replies are listed 'Best First'.
Re: Net::SSH2 with pty
by jfroebe (Parson) on Jul 07, 2009 at 03:50 UTC
      We are not trying to xdisplay. We are trying to use sudo to run admin commands with sudo like resetting the root passwd and rebooting the remote host.
Re: Net::SSH2 with pty
by salva (Canon) on Jul 08, 2009 at 22:06 UTC
    I don't know how to do it work with Net::SSH2 but with Net::OpenSSH and Expect it is pretty easy:
    use Net::OpenSSH; use Expect; my $ssh = Net::OpenSSH->new($host, password => $password); my ($pty, $pid) = $ssh->open2pty("sudo cat /etc/shadow") or die "open2pty failed: " . $ssh->error . "\n"; my $expect = Expect->init($pty); $expect->raw_pty(1); # $expect->log_user(1); $expect->expect($timeout, ':') or die "expect failed\n"; $expect->send("$password\n"); $expect->expect($timeout, "\n") or die "bad password\n"; while(<$pty>) { print "$. $_" }
    Code extracted from here!