本文深入探讨SSH连接失败、密钥管理、权限设置等常见难题并提供详细的解决方案。通过本文您将能够轻松应对SSH使用过程中遇到的各类问题提升SSH操作效率保障远程连接的安全性。1. Connection reset by peer现象ssh到server时报如下错误ssh_exchange_identification: read: Connection reset by peer解决方法方法一在sever端修改白名单vim /etc/hosts.allow添加sshd : ALL重启ssh服务service sshd restart方法二在sever端修改黑名单vim /etc/hosts.deny把中含客户端IP的删除掉试试重启ssh服务service sshd restart2. connection refused现象ssh: connect to host XX.XX.XX.XX port 22: Connection refused解决方法方法一检查目标主机的ssh server端程序是否安装、服务是否启动是否在侦听22端口ps -ef|grep sshdroot 2859 1 020:29 ? 00:00:00 /usr/sbin/sshd -D root 2901 2859 020:31 ? 00:00:00 sshd: june[priv] june 2971 2901 020:31 ? 00:00:00 sshd:junepts/1其中/usr/sbin/sshd为ssh clinet/server中server端的守护进程如果上述结果中没有sshd出现那么可能就是你的server端程序没有安装或者sshd服务没有启动方法二本机是否设置了iptables规则禁止了ssh的连入/连出sudo iptables -LChain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp – anywhere anywhere tcp dpt:ssh Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination3. SSL_ERROR_SYSCALL现象SSL_connect: SSL_ERROR_SYSCALL in connectiontogithub.com:443原因分析一般因为开了代理解决方法git config --global --unset http.proxy4. Permission denied (publickey)原因本地禁止免密登录sudo vim /etc/ssh/sshd_config找到PasswordAuthentication将PasswordAuthentication no改为yes保存接着使用命令sudo service ssh restart原因远端安全限制The following method might work if you can access machineA and machineB independently (e.g. from machineC).If ssh-copy-id is not working, password authentication could be disabled.The following is a workaround.Having machineAs public key in machineBs authorized keys (i.e. ~/.ssh/authorized_keys) will allow you to ssh from machineA. This also applies to scp.After generating the key pairs using:ssh-keygenOnmachineA, executecat ~/.ssh/id_rsa.pubSample output:ssh-rsa AAAAB3NzaSGMFZW7yB anaskmahineACopy the printed key (⌘ CommandC, or CRTLC) then add it to the ~/.ssh/authorized_keys file onmachineB.For example, execute the following onmachineB:echo ssh-rsa AAAAB3NzaSGMFZW7yB anaskmahineA ~/.ssh/authorized_keys参考文献SSH登录提示:connection refused的解决办法_ABC_ORANGE的博客-CSDN博客教你如何调试 SSH 连接使用ssh远程连接服务器Permission denied (publickey). 解决方法_ssh publickey denied_IT鹅的博客-CSDN博客server - SSH Permission denied (publickey) - Ask Ubuntu
ssh 使用问题汇总
发布时间:2026/5/16 21:59:47
本文深入探讨SSH连接失败、密钥管理、权限设置等常见难题并提供详细的解决方案。通过本文您将能够轻松应对SSH使用过程中遇到的各类问题提升SSH操作效率保障远程连接的安全性。1. Connection reset by peer现象ssh到server时报如下错误ssh_exchange_identification: read: Connection reset by peer解决方法方法一在sever端修改白名单vim /etc/hosts.allow添加sshd : ALL重启ssh服务service sshd restart方法二在sever端修改黑名单vim /etc/hosts.deny把中含客户端IP的删除掉试试重启ssh服务service sshd restart2. connection refused现象ssh: connect to host XX.XX.XX.XX port 22: Connection refused解决方法方法一检查目标主机的ssh server端程序是否安装、服务是否启动是否在侦听22端口ps -ef|grep sshdroot 2859 1 020:29 ? 00:00:00 /usr/sbin/sshd -D root 2901 2859 020:31 ? 00:00:00 sshd: june[priv] june 2971 2901 020:31 ? 00:00:00 sshd:junepts/1其中/usr/sbin/sshd为ssh clinet/server中server端的守护进程如果上述结果中没有sshd出现那么可能就是你的server端程序没有安装或者sshd服务没有启动方法二本机是否设置了iptables规则禁止了ssh的连入/连出sudo iptables -LChain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp – anywhere anywhere tcp dpt:ssh Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination3. SSL_ERROR_SYSCALL现象SSL_connect: SSL_ERROR_SYSCALL in connectiontogithub.com:443原因分析一般因为开了代理解决方法git config --global --unset http.proxy4. Permission denied (publickey)原因本地禁止免密登录sudo vim /etc/ssh/sshd_config找到PasswordAuthentication将PasswordAuthentication no改为yes保存接着使用命令sudo service ssh restart原因远端安全限制The following method might work if you can access machineA and machineB independently (e.g. from machineC).If ssh-copy-id is not working, password authentication could be disabled.The following is a workaround.Having machineAs public key in machineBs authorized keys (i.e. ~/.ssh/authorized_keys) will allow you to ssh from machineA. This also applies to scp.After generating the key pairs using:ssh-keygenOnmachineA, executecat ~/.ssh/id_rsa.pubSample output:ssh-rsa AAAAB3NzaSGMFZW7yB anaskmahineACopy the printed key (⌘ CommandC, or CRTLC) then add it to the ~/.ssh/authorized_keys file onmachineB.For example, execute the following onmachineB:echo ssh-rsa AAAAB3NzaSGMFZW7yB anaskmahineA ~/.ssh/authorized_keys参考文献SSH登录提示:connection refused的解决办法_ABC_ORANGE的博客-CSDN博客教你如何调试 SSH 连接使用ssh远程连接服务器Permission denied (publickey). 解决方法_ssh publickey denied_IT鹅的博客-CSDN博客server - SSH Permission denied (publickey) - Ask Ubuntu