I don’t know how to best put it but here is my problem:
I have two machines, Client A and a Server B.
My client is authenticated and does not need a password to connect to B normally. When I do an ssh from A to B it logs in without a password.
However,
When I use multiple parallel connections using the Parallel::Forkmanager module, it sometimes asks for password.
Here’s the code I use to make connections:
Code:
use Parallel:ForkManager;
my $pm=new Parallel::ForkManager(15);
foreach my $processNumber (1 .. 15) {
$pm->start and next;
<subroutine to ssh to the server and perform some actions>;
$pm->finish;
}
$pm->wait_all_children;
Every process has about 5000 more iterations of creating some tables etc.
Intermittently, it asks for password to authenticate the client when it normally does not.
My ssh keys are saved on the server.
What could be the problem? Any help is appreciated.
I’ve usually seen this behavior when you hit the maximum simultaneous count of connections that are pending authentication on the remote server’s sshd. The default is 10, and since you are using 15 forked children you could certainly reach that limit occasionally.
Some solutions:
/etc/ssh/sshd_configon the server and increaseMaxStartupssleep $processNumber;at the top of yourforeachloop to ensure that the connections are staggered.Unrelated, but you probably will want to invoke ssh with
-O BatchMode=yeson the command-line to prevent it from ever interactively prompting you for password or key confirmations. It will instead fail and exit with non-zero, making it easier for your script to detect and handle errors gracefully.