Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Net::SSH2 with pty

by kmitchellwr (Initiate)
on Jul 06, 2009 at 21:20 UTC ( [id://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 (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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found