gpt4 book ai didi

linux + ssh 限制 + ssh 同时从多台机器到一台机器

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:31:02 27 4
gpt4 key购买 nike

下面的脚本“testssh.ksh”证明当我们尝试同时从多台机器执行ssh时ssh有一些问题

实际上这个脚本的目标是验证Solaris服务器(10.10.18.6)中/var/tmp下的文件test_file,正如大家看到的一些ssh步骤我们无法验证test_file 的存在,因为 ssh 卡住或未从 expect 激活

背景 - 此脚本同时对 IP - 10.10.18.6 的 Solaris 服务器执行 15 次 ssh,以验证服务器中/var/tmp 下的 file_test

我的问题-如何改进ssh进程以避免以下问题

备注 - 在这种情况下 sleep 可以帮助我们 - 但我不想在 ssh 进程之前添加 sleep

  [root@linux /var/tmp]# more  testssh.ksh
#!/bin/ksh



expect=`cat << EOF
set timeout -1
spawn ssh 10.10.18.6
expect {
")?" { send "yes\r" ; exp_continue }

word: {send pass123\r}
}
expect > {send "ls /var/tmp/test_file\r"}
expect > {send exit\r}
expect eof
EOF`


for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
do
( expect -c "$expect" | grep "test_file" | grep -v ls ) &
done

示例 - 当我们运行脚本 testssh.ksh 时

     [root@linux /var/tmp]# /var/tmp/testssh.ksh
/var/tmp/test_file
/var/tmp/test_file
/var/tmp/test_file
/var/tmp/test_file
/var/tmp/test_file
expect: spawn id exp6 not open
while executing
"expect > {send "ls /var/tmp/test_file\r"}"
expect: spawn id exp6 not open
while executing
"expect > {send "ls /var/tmp/test_file\r"}"
expect: spawn id exp6 not open
while executing
"expect > {send "ls /var/tmp/test_file\r"}"
expect: spawn id exp6 not open
while executing
"expect > {send "ls /var/tmp/test_file\r"}"
/var/tmp/test_file
/var/tmp/test_file
/var/tmp/test_file
/var/tmp/test_file
/var/tmp/test_file
/var/tmp/test_file

最佳答案

您是否在 sshd.conf(或等效文件)中设置了 MaxSessionMaxStartups?我相信 40 个并发 SSH 连接对于您的服务器来说应该不会太多。

来自 man sshd_config 页面:

 MaxSessions
Specifies the maximum number of open sessions permitted per net‐
work connection. The default is 10.

MaxStartups
Specifies the maximum number of concurrent unauthenticated con‐
nections to the SSH daemon. Additional connections will be
dropped until authentication succeeds or the LoginGraceTime
expires for a connection. The default is 10.

Alternatively, random early drop can be enabled by specifying the
three colon separated values “start:rate:full” (e.g. "10:30:60").
sshd(8) will refuse connection attempts with a probability of
“rate/100” (30%) if there are currently “start” (10) unauthenti‐
cated connections. The probability increases linearly and all
connection attempts are refused if the number of unauthenticated
connections reaches “full” (60).

如果您没有更改这些,您的服务器将不会同时处理超过 10 个连接。

Similar question (serverfault.com)。

关于linux + ssh 限制 + ssh 同时从多台机器到一台机器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9257958/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com