thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am using the Net::OpenSSH::Parallel module to create parallel ssh connections. Note that the module is using the Net::OpenSSH to create ssh sessions. So far I have successfully used in the past for multiple scripts by using password => $password in public the username and password to automate ssh connections
As stated on the documentation: Note that using password authentication in automated scripts is a very bad idea. When possible, you should use public key authentication instead. it is much safer to use ssh key authentication.
I am able to ssh to my localhost through the typical way
to automate the connections without password but with ssh-key on debug mode -1 $Net::OpenSSH::Parallel::debug = -1;, I keep getting this error:ssh -p 22 user@host</p> without password as I have set up the ssh key +authentication.</p> <p>When I am using the module <code>Net::OpenSSH::Parallel
0.488| [192.168.24.16] added (HASH(0x19e5f70)) 0.488| [192.168.24.16] state set to done 0.488| selector(*) --> [192.168.24.16] 0.488| [192.168.24.16] action command queued 0.488| [192.168.24.16] state changed done --> ready 0.488| run: iterating... 0.488| run: hosts at connecting: 0 0.488| run: hosts at ready: 1 0.488| num workers: 1, maximum: 1 0.488| [192.168.24.16] at_ready 0.488| [192.168.24.16] at_ready, starting new action command 0.488| [192.168.24.16] host is not connected, connecting... 0.488| [192.168.24.16] _connect, starting SSH connection Invalid or bad combination of options ('key_path') at parallel_ssh.pl +line 41.
I wrote a small script to demonstrate the problem that I am having:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::OpenSSH::Parallel; $Net::OpenSSH::Parallel::debug = -1; my %hosts = ( 'localhost' => { host => "127.0.0.1", user => "user", port => "22", psw => "psw", key => "/home/user/.ssh/id_rsa", }, ); my $maximum_workers = scalar (keys %hosts); my $maximum_connections = 2 * $maximum_workers; my $maximum_reconnections = 0; my %opts = ( workers => $maximum_workers, connections => $maximum_connections, reconnections => $maximum_reconnections ); my $pssh = Net::OpenSSH::Parallel->new( %opts ); foreach my $label (keys %hosts) { $pssh->add_host( #$hosts{$label}, $hosts{$label}{host}, user => $hosts{$label}{user}, port => $hosts{$label}{port}, password => $hosts{$label}{psw}, key_path => $hosts{$label}{key}, ); } #print Dumper $pssh; $pssh->push('*', command => 'ls'); $pssh->run;
If someone searches for the same error online he will find multiple links for similar errors but none of them providing the solution to the problem, example links (Re: net::openssh error in CGI: Invalid or bad combination of options ('key_path')). The only useful link that I found is (how to use Net::SSH::Perl with public keys?).
The error is coming from the module Net::OpenSSH (github link) at line 69.
Anyone ever encounter this problem, and if so does anyone know how to overcome the problem?
Thanks in advance for your time and effort reading and replying to my question.
Update: ok I just found the solution to my problem (stupid of me). I just thought that might provide some help to someone in future that is the only reason that I am posting this.
Solution: simply since you obviously using ssh-key what is the purpose to use password. Simply comment out the password input when you add another user or simply do not provide it.
End of update
|
|---|