尽管在使用 Parallel:ForkManager 时安装了 ssh 密钥,服务器仍提示输入密码

发布于 2024-12-04 00:04:43 字数 580 浏览 0 评论 0原文

我不知道如何最好地表达它,但这是我的问题: 我有两台机器,客户端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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恋竹姑娘 2024-12-11 00:04:43

当您达到远程服务器 sshd 上等待身份验证的连接的最大同时计数时,我通常会看到这种行为。默认值为 10,并且由于您使用 15 个分叉子项,您肯定偶尔会达到该限制。

一些解决方案:

  1. 在服务器上编辑 /etc/ssh/sshd_config 并增加 MaxStartups
  2. 或者,您可以尝试在服务器上添加 sleep $processNumber; foreach 循环的顶部,以确保连接是交错的。
  3. 或者只是将进程计数从 15 减少到 10 或更低。

不相关,但您可能需要在命令行上使用 -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:

  1. Edit /etc/ssh/sshd_config on the server and increase MaxStartups
  2. Alternatively, you can try adding a sleep $processNumber; at the top of your foreach loop to ensure that the connections are staggered.
  3. Or just reduce your process count from 15 to a value of 10 or lower.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文