[Ssh-sftp-perl-users] login using scripted password?
Brought to you by:
dbrobins
From: Mike W. <mwa...@uu...> - 2009-07-09 20:38:55
|
Hello! I am trying to write a script using the Net::SSH:Perl module to automatically login to several remote machines on my network. I understand the security implications of this; the script is a one-off to automate what would be a really tedious job to do by hand. Unfortunately, the $ssh->login($username, $password) portion of the script seems to be ignoring the $password. Here's the script: ----------------------------Start Script---------------------------- #! /usr/bin/perl use strict; use Net::SSH::Perl; # Username, password and IP address have been altered since this is # being posted in a public forum. my $cmd = "uname -a; exit"; my $host= "192.168.244.26"; my $ssh = Net::SSH::Perl->new($host, protocol=>'2', debug=>'true', #interactive=>'false', options=>["BatchMode yes"]); $ssh->login("myusername","mypassword"); my ($stdout, $stderr, $exit) = $ssh->cmd($cmd); if ($exit == 0) { print "$stdout\n\n"; } else { warn("Unable to access ${host}: ${stderr}\n"); } -----------------------------End Script----------------------------- When I run the script with "interactive=>'false'" commented out (as shown above), I get the following output: ----------------------------Start Output---------------------------- user@desktop: ~/development/perl $ myscript.pl desktop: Reading configuration data /home/user/.ssh/config desktop: Reading configuration data /etc/ssh_config desktop: Connecting to 192.168.244.26, port 22. desktop: Remote protocol version 2.0, remote software version OpenSSH_5.2 desktop: Net::SSH::Perl Version 1.34, protocol version 2.0. desktop: No compat match: OpenSSH_5.2 desktop: Connection established. desktop: Sent key-exchange init (KEXINIT), wait response. desktop: Algorithms, c->s: 3des-cbc hmac-sha1 none desktop: Algorithms, s->c: 3des-cbc hmac-sha1 none desktop: Entering Diffie-Hellman Group 1 key exchange. desktop: Sent DH public key, waiting for reply. desktop: Received host key, type 'ssh-dss'. desktop: Host '192.168.244.26' is known and matches the host key. desktop: Computing shared secret key. desktop: Verifying server signature. desktop: Waiting for NEWKEYS message. desktop: Send NEWKEYS. desktop: Enabling encryption/MAC/compression. desktop: Sending request for user-authentication service. desktop: Service accepted: ssh-userauth. desktop: Trying empty user-authentication request. desktop: Authentication methods that can continue: publickey,keyboard-interactive. desktop: Next method to try is publickey. desktop: Publickey: testing agent key '' desktop: Authentication methods that can continue: publickey,keyboard-interactive. desktop: Next method to try is publickey. desktop: Next method to try is keyboard-interactive. Password: ^C user@desktop: ~/development/perl $ -----------------------------End Output----------------------------- On the other hand, if I leave "interactive=>'false'" in the script, I get...: ----------------------------Start Output---------------------------- user@desktop ~/development/perl $ ./myscript.pl desktop: Reading configuration data /home/user/.ssh/config desktop: Reading configuration data /etc/ssh_config desktop: Connecting to 192.168.244.26, port 22. desktop: Remote protocol version 2.0, remote software version OpenSSH_5.2 desktop: Net::SSH::Perl Version 1.34, protocol version 2.0. .ikemachine: No compat match: OpenSSH_5.2 desktop: Connection established. desktop: Sent key-exchange init (KEXINIT), wait response. desktop: Algorithms, c->s: 3des-cbc hmac-sha1 none desktop: Algorithms, s->c: 3des-cbc hmac-sha1 none desktop: Entering Diffie-Hellman Group 1 key exchange. desktop: Sent DH public key, waiting for reply. desktop: Received host key, type 'ssh-dss'. desktop: Host '192.168.244.26' is known and matches the host key. desktop: Computing shared secret key. desktop: Verifying server signature. desktop: Waiting for NEWKEYS message. desktop: Send NEWKEYS. desktop: Enabling encryption/MAC/compression. desktop: Sending request for user-authentication service. desktop: Service accepted: ssh-userauth. desktop: Trying empty user-authentication request. desktop: Authentication methods that can continue: publickey,keyboard-interactive. desktop: Next method to try is publickey. desktop: Publickey: testing agent key '' desktop: Authentication methods that can continue: publickey,keyboard-interactive. desktop: Next method to try is publickey. desktop: Next method to try is keyboard-interactive. Password: desktop: Login completed, opening dummy shell channel. desktop: channel 0: new [client-session] desktop: Requesting channel_open for channel 0. desktop: channel 0: open confirm rwindow 0 rmax 32768 desktop: Got channel open confirmation, requesting shell. desktop: Requesting service shell on channel 0. desktop: channel 1: new [client-session] desktop: Requesting channel_open for channel 1. desktop: Entering interactive session. desktop: Sending command: uname -a; exit desktop: Sending command: uname -a; exit desktop: Requesting service exec on channel 1. desktop: channel 1: open confirm rwindow 0 rmax 32768 desktop: channel 1: rcvd eof desktop: channel 1: output open -> drain desktop: input_channel_request: rtype exit-status reply 0 desktop: channel 1: rcvd close desktop: channel 1: input open -> closed desktop: channel 1: close_read desktop: channel 1: obuf empty desktop: channel 1: output drain -> closed desktop: channel 1: close_write desktop: channel 1: send close desktop: channel 1: full closed Linux desktop.uui-alaska.com 2.6.29-gentoo-r5 #2 SMP PREEMPT Wed Jun 10 09:50:55 AKDT 2009 i686 Genuine Intel(R) CPU T2600 @ 2.16GHz GenuineIntel GNU/Linux user@desktop ~/development/perl $ -----------------------------End Output----------------------------- I don't understand why Net::SSH::Perl isn't using the scripted password to login in at least one of these variations. Does anyone know what it is I am doing wrong? Thanks! --Mike Wallette Assistant Network Administrator, United Utilities, Inc. -- On time, under budget. Now with 98% uptime! |