Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Net::SSH2 with pty

by kmitchellwr (Initiate)
on Jul 06, 2009 at 21:20 UTC ( #777688=perlquestion: print w/replies, xml ) Need Help??
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 (Abbot) 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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://777688]
Approved by AnomalousMonk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-05-24 00:02 GMT
Find Nodes?
    Voting Booth?