El Módulo Net::SSH::Expect

Véase Net::SSH::Expect:

casiano@beowulf:~$ pp2@nereida:~/src/testing$ cat -n netsshexpect.pl
 1  #!/usr/bin/perl -w
 2  use strict;
 3  use Net::SSH::Expect;
 4
 5  my $host="xxxxxxx";
 6  my $password="XXXXXXXXXXXXXX";
 7  my $user="XXXXX";
 8
 9  my $ssh= Net::SSH::Expect->new( host => $host,
10                                  password=> $password,
11                                  user => $user,
12                                  raw_pty =>1);
13  $ssh->login();
14
15  my $who = $ssh->exec("who");
16  print ($who);
17
18  $ssh->close();

Ejecución

pp2@nereida:~/src/testing$ netsshexpect.pl
casiano  pts/0        2008-04-08 16:40 (nereida)
casiano  pts/1        2008-04-08 15:31 (nereida)
casiano  pts/2        2008-04-08 17:52 (nereida)
casiano  pts/3        2008-04-08 17:55 (nereida)



Subsecciones
Casiano Rodríguez León
2010-03-22
87 my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); 88 $packet->put_str($new_password); 89 $packet->send; 90 } 91 }); 92 93 ## After registering the handler, we run the command. 94 95 $ssh->cmd('passwd');

Véase un ejemplo de ejecución:

pp2@nereida:/tmp$ remoteinteract.pl
local.host: Reading configuration data /home/pp2/.ssh/config
local.host: Reading configuration data /etc/ssh_config
local.host: Connecting to some.remote.host, port 22.
local.host: Remote version string: SSH-2.0-OpenSSH_4.7p1 Debian-9

local.host: Remote protocol version 2.0, remote software version OpenSSH_4.7p1 Debian-9
local.host: Net::SSH::Perl Version 1.30, protocol version 2.0.
local.host: No compat match: OpenSSH_4.7p1 Debian-9.
local.host: Connection established.
local.host: Sent key-exchange init (KEXINIT), wait response.
local.host: Algorithms, c->s: 3des-cbc hmac-sha1 none
local.host: Algorithms, s->c: 3des-cbc hmac-sha1 none
local.host: Entering Diffie-Hellman Group 1 key exchange.
local.host: Sent DH public key, waiting for reply.
local.host: Received host key, type 'ssh-dss'.
local.host: Host 'some.remote.host' is known and matches the host key.
local.host: Computing shared secret key.
local.host: Verifying server signature.
local.host: Waiting for NEWKEYS message.
local.host: Enabling incoming encryption/MAC/compression.
local.host: Send NEWKEYS, enable outgoing encryption/MAC/compression.
local.host: Sending request for user-authentication service.
local.host: Service accepted: ssh-userauth.
local.host: Trying empty user-authentication request.
local.host: Authentication methods that can continue: publickey,password.
local.host: Next method to try is publickey.
local.host: Trying pubkey authentication with key file '/home/pp2/.ssh/id_dsa'
local.host: Authentication methods that can continue: publickey,password.
local.host: Next method to try is publickey.
local.host: Next method to try is password.
local.host: Trying password authentication.
local.host: Login completed, opening dummy shell channel.
local.host: channel 0: new [client-session]
local.host: Requesting channel_open for channel 0.
local.host: channel 0: open confirm rwindow 0 rmax 32768
local.host: Got channel open confirmation, requesting shell.
local.host: Requesting service shell on channel 0.
local.host: channel 1: new [client-session]
local.host: Requesting channel_open for channel 1.
local.host: Entering interactive session.
local.host: Sending command: passwd
local.host: Requesting service exec on channel 1.
local.host: channel 1: open confirm rwindow 0 rmax 32768
---------   <- MODO INTERACTIVO: old password
*********   <- MODO INTERACTIVO: new password
*********   <- MODO INTERACTIVO: repeat new password
local.host: input_channel_request: rtype exit-status reply 0
local.host: channel 1: rcvd eof
local.host: channel 1: output open -> drain
local.host: channel 1: rcvd close
local.host: channel 1: input open -> closed
local.host: channel 1: close_read
local.host: channel 1: obuf empty
local.host: channel 1: output drain -> closed
local.host: channel 1: close_write
local.host: channel 1: send close
local.host: channel 1: full closed

Casiano Rodríguez León
2010-04-19