dayton has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to setup a script using Net::SSH::Perl to connect to several hosts and need some insight.. I'm able to connect either with password or rsa/dsa key as long as I specify the username - however on a few hosts the user name is different (and defined in my ~/.ssh/config) How can I get my script to grab the "User" value from the "Hostname" in my config file?
foreach $host (@HOSTS) { $ssh = Net::SSH::Perl->new("$host",debug=>1,option +s => ["ConnectTimeout=5","StrictHostKeyChecking=no"]); $ssh->login($user); ($out, $err, $exit)=$ssh->cmd($exec_cmd); }
per the debug, it's reading my config but not getting the User for a particular host:
Host host2 hostname host2.mydomain User user1
my_host: Reading configuration data /home/djones/.ssh/config my_host: Reading configuration data /etc/ssh_config my_host: Connecting to host2, port 22. my_host: Remote version string: SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7. +1 my_host: Remote protocol version 2.0, remote software version OpenSSH_ +5.3p1 Debian-3ubuntu7.1 my_host: Net::SSH::Perl Version 1.36, protocol version 2.0. .y_host: No compat match: OpenSSH_5.3p1 Debian-3ubuntu7.1 my_host: Connection established. my_host: Sent key-exchange init (KEXINIT), wait response. my_host: Algorithms, c->s: 3des-cbc hmac-sha1 none my_host: Algorithms, s->c: 3des-cbc hmac-sha1 none my_host: Entering Diffie-Hellman Group 1 key exchange. my_host: Sent DH public key, waiting for reply. my_host: Received host key, type 'ssh-dss'. my_host: Host 'host2' is known and matches the host key. my_host: Computing shared secret key. my_host: Verifying server signature. my_host: Waiting for NEWKEYS message. my_host: Send NEWKEYS. my_host: Enabling encryption/MAC/compression. my_host: Sending request for user-authentication service. my_host: Service accepted: ssh-userauth. my_host: Trying empty user-authentication request. my_host: Authentication methods that can continue: publickey,password. my_host: Next method to try is publickey. my_host: Publickey: testing agent key '/home/djones/.ssh/id_dsa' my_host: Authentication methods that can continue: publickey,password. my_host: Next method to try is publickey. my_host: Next method to try is password. my_host: Trying password authentication. my_host: Will not query passphrase in batch mode. my_host: Authentication methods that can continue: publickey,password. my_host: Next method to try is publickey. my_host: Publickey: testing agent key '/home/djones/.ssh/id_dsa' my_host: Authentication methods that can continue: publickey,password. my_host: Next method to try is publickey. Received disconnect message: Too many authentication failures for djon +es at /usr/share/perl5/vendor_perl/Net/SSH/Perl/AuthMgr.pm line 143.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH::Perl and getting User from config
by salva (Canon) on May 02, 2015 at 06:52 UTC | |
|
Re: Net::SSH::Perl and getting User from config
by pme (Monsignor) on May 02, 2015 at 07:23 UTC | |
|
Re: Net::SSH::Perl and getting User from config
by Don Coyote (Hermit) on May 02, 2015 at 08:21 UTC | |
by dayton (Acolyte) on May 06, 2015 at 15:16 UTC |