StrictHostKeyChecking
来源:互联网 发布:网络ip加速 编辑:程序博客网 时间:2024/06/07 20:22
SSH 公钥检查是一个重要的安全机制,可以防范中间人劫持等黑客攻击。但是在特定情况下,严格的 SSH 公钥检查会破坏一些依赖 SSH 协议的自动化任务,就需要一种手段能够绕过 SSH 的公钥检查。
首先看看什么是 SSH 公钥检查
SSH 连接远程主机时,会检查主机的公钥。如果是第一次该主机,会显示该主机的公钥摘要,提示用户是否信任该主机: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)?当选择接受,就会将该主机的公钥追加到文件 ~/.ssh/known_hosts 中。当再次连接该主机时,就不会再提示该问题了。 如果因为某种原因(服务器系统重装,服务器间IP地址交换,DHCP,虚拟机重建,中间人劫持),该IP地址的公钥改变了,当使用 SSH 连接的时候,会报错:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 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 ise9: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:81RSA host key for 192.168.0.110 has changed and you have requested strict checking.Host key verification failed.上面的警告信息说的是:
- 服务器公钥已经改变,新的公钥的摘要是:e9:0c:36:89:7f:3c:07:71:09:5a:9f:28:8c:44:e9:05.
- 该服务器原来的公钥记录在文件 ~/.ssh/known_hosts 中第 81 行。
如何让连接新主机时,不进行公钥确认?
在首次连接服务器时,会弹出公钥确认的提示。这会导致某些自动化任务,由于初次连接服务器而导致自动化任务中断。或者由于 ~/.ssh/known_hosts 文件内容清空,导致自动化任务中断。 SSH 客户端的 StrictHostKeyChecking 配置指令,可以实现当第一次连接服务器时,自动接受新的公钥。只需要修改 /etc/ssh/ssh_config 文件,包含下列语句:Host * StrictHostKeyChecking no或者在 ssh 命令行中用 -o 参数
$ ssh -o StrictHostKeyChecking=no 192.168.0.110
如何防止远程主机公钥改变导致 SSH 连接失败
当确认中间人劫持攻击风险比较小的情况下,才可以使用下面的方法,禁用 SSH 远程主机的公钥检查。 SSH 客户端提供一个 UserKnownHostsFile 配置,允许指定不同的 known_hosts 文件。那么将 known_hosts 指向不同的文件,不就不会造成公钥冲突导致的中断了么?$ ssh -o UserKnownHostsFile=/dev/null 192.168.0.110The authenticity of host '192.168.0.110 (192.168.0.110)' can't be established.RSA key fingerprint is e9:0c:36:89:7f:3c:07:71:09:5a:9f:28:8c:44:e9:05.Are you sure you want to continue connecting (yes/no)?看,提示信息由公钥改变中断警告,变成了首次连接的提示。 和之前提到的 StrictHostKeyChecking 配置配合使用,则不再有任何警告出现了:
$ ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null 192.168.0.110Warning: Permanently added '192.168.0.110' (RSA) to the list of known hosts.jiangxin@192.168.0.110's password:
如果设置了无口令 SSH 登录(即通过客户端公钥认证),就可以直接连接到远程主机。这是基于 SSH 协议的自动化任务常用的手段。
Jsch
Properties sshConfig = new Properties();
sshConfig.put("StrictHostKeyChecking", "no");
sshSession.setConfig(sshConfig);
阅读全文
0 0
- StrictHostKeyChecking
- ssh StrictHostKeyChecking
- angularjs 公告框:记录,搜索,弹框提示,
- kubernetes1.5.2部署项目demo
- Kotlin 基础学习
- Intellij IDEA中使用MyBatis plugin插件安装教程及破解方法
- java的HttpURLConnection类封装好的GET/POST请求工具类
- StrictHostKeyChecking
- Java日志管理:common-logging、slf4j、log4j、logback的关系
- DevSecOps及机器学习:对IT安全变化的影响
- HDU 3342 Legal or Not | HDU 5154 (拓扑排序判环)
- 跨域post请求 CORS
- 欢迎使用CSDN-markdown编辑器
- 揭开Socket的神秘面纱
- Linux安装telnet
- android studio翻译插件ECTranslation