使用StrictHostKeyChecking选项,例如:
ssh -oStrictHostKeyChecking=no $h uptime
此选项也可以添加到〜/ .ssh / config中,例如:
Host somehost
Hostname 10.0.0.1
StrictHostKeyChecking no
请注意,更改主机密钥后,即使使用此选项,也会收到警告:
$ ssh -oStrictHostKeyChecking=no somehost uptime
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
31:6f:2a:d5:76:c3:1e:74:f7:73:2f:96:16:12:e0:d8.
Please contact your system administrator.
Add correct host key in /home/peter/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/peter/.ssh/known_hosts:24
remove with: ssh-keygen -f "/home/peter/.ssh/known_hosts" -R 10.0.0.1
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
ash: uptime: not found
如果不经常重新安装主机,则可以使用该选项降低安全性(但对于经常更改的主机密钥来说更方便)-oUserKnownHostsFile=/dev/null
。这将丢弃所有接收到的主机密钥,因此它将永远不会生成警告。
在18.04版本中,有一种新的可能性:StrictHostKeyChecking=accept-new
。来自man 5 ssh_config
:
If this flag is set to “accept-new” then ssh will automatically
add new host keys to the user known hosts files, but will not
permit connections to hosts with changed host keys. If this flag
is set to “no” or “off”, ssh will automatically add new host keys
to the user known hosts files and allow connections to hosts with
changed hostkeys to proceed, subject to some restrictions.
yes
输出“ y”,因此您可能会比较幸运for h in $SERVER_LIST; do yes yes | ssh $h "uptime"; done
(请注意额外的yes,它表示yes而不是“ y” ”)。