如何在 docker 上使用 -o StrictHostKeyChecking=no 运行 进行 ssh,以便 ssh 主机在不退出脚本执行的情况下工作?

How to make the ssh with -o StrictHostKeyChecking=no running on the docker in order to ssh the host work without exiting the script execution?

我有一个脚本,即 运行 在 docker 容器内 我们需要一些内部调试目的的操作:

set -eu
echo "Starting i/o test for host"
IP_HOST=$(ip a | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | grep 172.17 | awk 'NR==1{print }')
echo "Detected IP of host is $IP_HOST"
sshpass -p tcuser ssh -o StrictHostKeyChecking=no docker@localhost -t -t
echo "Then"

这里的输出正好是:

bash-5.0# sh /etc/cron.d/iotesthost.sh
Mon Mar  2 12:43:59 UTC 2020
Starting i/o test for host
Detected IP of host is 172.17.0.1
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

当到达最后一行时,脚本让我退出 bashcrond 执行。所以我无法在 sshpass/ssh 之后继续处理其他行,所以我永远不会到达 echo "Then"

这就是退出脚本执行的原因以及如何解决它,仍然保留接受密钥的所有功能(我需要的是每次 docker 容器调用脚本时它都是新的)

如果我忽略 -t -t,我会根据

收到错误

https://askubuntu.com/questions/87449/how-to-disable-strict-host-key-checking-in-ssh

echo "StrictHostKeyChecking no" >> /etc/ssh_config

寻求全球解决方案。请注意,届时将不再进行安全检查。