尽管在使用 Parallel:ForkManager 时安装了 ssh 密钥,服务器仍提示输入密码
我不知道如何最好地表达它,但这是我的问题: 我有两台机器,客户端A和服务器B。 我的客户端已通过身份验证,不需要密码即可正常连接到 B。当我从 A 到 B 执行 ssh 时,它无需密码即可登录。
然而, 当我使用 Parallel::Forkmanager 模块使用多个并行连接时,它有时会要求输入密码。
这是我用来建立连接的代码: 代码: 使用并行: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;
每个过程都有大约 5000 次以上的迭代来创建一些表等。 它会间歇性地要求输入密码来对客户端进行身份验证,而通常情况下不会这样做。
我的 ssh 密钥保存在服务器上。
可能是什么问题?任何帮助表示赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您达到远程服务器 sshd 上等待身份验证的连接的最大同时计数时,我通常会看到这种行为。默认值为 10,并且由于您使用 15 个分叉子项,您肯定偶尔会达到该限制。
一些解决方案:
/etc/ssh/sshd_config
并增加MaxStartups
sleep $processNumber;
foreach
循环的顶部,以确保连接是交错的。不相关,但您可能需要在命令行上使用
-O BatchMode=yes
调用 ssh,以防止它以交互方式提示您输入密码或密钥确认。相反,它会失败并以非零值退出,从而使您的脚本更容易优雅地检测和处理错误。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_config
on the server and increaseMaxStartups
sleep $processNumber;
at the top of yourforeach
loop to ensure that the connections are staggered.Unrelated, but you probably will want to invoke ssh with
-O BatchMode=yes
on 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.