我有一个脚本,它在 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 $1}')
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
到达最后一行时,脚本使我退出 bash 或 crond 执行。因此,我无法在 sshpass/ssh
之后继续处理其他行,因此我永远不会达到 echo "Then"
这就是退出脚本执行的原因以及如何解决它,仍然保留接受 key 的所有功能(我需要的是每次 docker 容器调用脚本时它都是新的)
如果我忽略 -t -t
,我会收到错误 https://stackoverflow.com/a/7122115/1759063
最佳答案
参见https://askubuntu.com/questions/87449/how-to-disable-strict-host-key-checking-in-ssh
或
echo "StrictHostKeyChecking no" >> /etc/ssh_config
全局解决方案。请注意,届时不再有安全检查。
关于bash - 如何使 ssh 与 -o StrictHostKeyChecking=no 在 docker 上运行,以便 ssh 主机工作而不退出脚本执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60489412/