运维工程师经常会使用ssh远程登录主机。ssh的使用并不复杂,但是也有可能会遇到各种各样的错误,我在本篇博文中总结了一些常见的ssh报错信息与解决方法。
Connection refused
可能原因:
- 网络出现问题
- ssh服务状态出现问题
- 防火墙原因
解决思路:
- 网络问题的解决方案这里就不再赘述
- ssh服务问题:
systemctl status sshd
netstat -anp |grep :22
- 防火墙问题:
firewall-cmd --add-port=22/tcp
iptables -L
Host key verification failed
可能原因:访问者使用的公钥与服务器记录不一致
解决思路:
- 在/etc/ssh/ssh_config中修改配置
StrictHostKeyChecking no
- 直接删除known_hosts文件
rm -rf /root/.ssh/known_hosts
免密登录失败(公私钥确定正确)
解决方法:
- 删除known_hosts,重新把id_rsa.pub添加到服务器~/.ssh/authorized_keys下
- 权限问题:
chmod -R 700 /root/.ssh
密码连接,密码正确,出现Permission denied, please try again
可能原因:
- /etc/ssh/sshd_config的PasswordAuthentication或PermitRootLogin参数配置问题
- 要连接的这台服务器的ip地址与你局域网中的某台电脑的ip地址一致,造成冲突
解决思路:
- PasswordAuthentication
vim /etc/ssh/sshd_config
将 PasswordAuthentication 前面的#号去掉
将 PasswordAuthentication 设为yes
systemctl restart sshd
- PermitRootLogin
vim /etc/ssh/sshd_config
将 PermitRootLogin 前面的#号去掉
将 PermitRootLogin 设为yes
systemctl restart sshd
Permission denied, please try againssh_exchange_identification: read: Connection reset by peer
可能原因:所访问的服务器启用了tcp_wrapper,拒绝接受该ip或网段发起访问的服务
解决方法:联系管理员打开ip限制
vim /etc/hosts.allow
sshd:all:allow