Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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.

Comment on Net::SSH2 with pty
Re: Net::SSH2 with pty
by jfroebe (Vicar) 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 (Monsignor) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://777688]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2014-04-16 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls