Re: [Ssh-sftp-perl-users] login using scripted password?
Brought to you by:
dbrobins
From: Mike W. <mwa...@uu...> - 2009-07-09 23:31:10
|
Yeah, but I goofed on the output I provided <sheepish> Both samples had "interactive=>'false'" set, but in one case, I manually entered the password when prompted. When "interactive=>'false'" is commented out, here's what the output *really* looks like: 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. Permission denied at ./myscript.pl line 14 user@desktop ~/development/perl $ Notice that it gives me the error message "Permission denied at ./myscript.pl line 14". The only thing that changed in this example is that I added the "#" to the beginning of line 11. Sorry for the confusion -- multitasking just provides new opportunities to embarrass yourself on-line :/ --Mike Howard, Chris wrote: > When you had interactive=>false didn't it give you the uname output? > >> -----Original Message----- >> From: Mike Wallette [mailto:mwa...@uu...] >> Sent: Thursday, July 09, 2009 4:59 PM >> To: Howard, Chris >> Subject: Re: [Ssh-sftp-perl-users] login using scripted password? >> >> No, it's prompting for a password. I was trying to hard-code the >> password in the script so that it could work unattended. The ultimate >> aim is to have an array of hosts to check, then cycle through the hosts >> in a "for" loop. I'm wanting to audit 103 hosts; I really don't want >> to >> type the password by hand that many times :) >> >> --Mike >> >> Howard, Chris wrote: >>> Looks to me like it worked! >>> >>> >>> >>>> -----Original Message----- >>>> From: Mike Wallette [mailto:mwa...@uu...] >>>> Sent: Thursday, July 09, 2009 2:27 PM >>>> To: ssh...@li... >>>> Subject: [Ssh-sftp-perl-users] login using scripted password? >>>> >>>> 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! >>>> >>>> >>> --------------------------------------------------------------------- >> -- >>>> ------- >>>> Enter the BlackBerry Developer Challenge >>>> This is your chance to win up to $100,000 in prizes! For a limited >>>> time, >>>> vendors submitting new applications to BlackBerry App World(TM) will >>>> have >>>> the opportunity to enter the BlackBerry Developer Challenge. See >> full >>>> prize >>>> details at: http://p.sf.net/sfu/Challenge >>>> _______________________________________________ >>>> Ssh-sftp-perl-users mailing list >>>> Ssh...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users >> -- >> On time, under budget. Now with 98% uptime! -- On time, under budget. Now with 98% uptime! |