ssh rsync 登陆时跳过host检查

SSH 公钥检查是一个重要的安全机制,可以防范中间人劫持等黑客攻击。不过我在做rsync的自动化任务时就遇到问题了:因为我的rsync的server和client都是容器启动的,host变化是很正常的事。所以必须要绕过这样的提醒错误:

The authenticity of host '192.168.0.110 (192.168.0.110)' can't be established.
RSA key fingerprint is a3:ca:ad:95:a1:45:d2:57:3a:e9:e7:75:a8:4c:1f:9f.
Are you sure you want to continue connecting (yes/no)?

或者

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
e9:0c:36:89:7f:3c:07:71:09:5a:9f:28:8c:44:e9:05.
Please contact your system administrator.
Add correct host key in /home/jiangxin/.ssh/known_hosts to get rid of this message.
Offending key in /home/jiangxin/.ssh/known_hosts:81
RSA host key for 192.168.0.110 has changed and you have requested strict checking.
Host key verification failed.

在ssh配置文件中配置如下即可:

vi ~/.ssh/config 

Host 192.168.1.10
   StrictHostKeyChecking no
   UserKnownHostsFile=/dev/null

或者批量设置:

vi ~/.ssh/config 

Host 192.168.0.*
   StrictHostKeyChecking no
   UserKnownHostsFile=/dev/null

参考资料


如果本文对你有帮助,欢迎投食

专利相关备忘 没有ESC键,在 iPad 上触发 Escape