我在 OS X 上尝试通过 ssh 连接到 ubuntu 12.04 服务器。我能够通过 SSH 进入 - 直到突然停止工作。我已经在线阅读以使用-v来调试它。输出如下所示。如果我 ssh 进入另一个盒子,然后从那个盒子 ssh 到服务器,我就可以登录。我不知道如何调试这个问题,但想学习。
$ ssh -v me@server
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug1: Connecting to server [IP] port 22.
debug1: Connection established.
debug1: identity file /Users/me/.ssh/id_rsa type 1
debug1: identity file /Users/me/.ssh/id_rsa-cert type -1
debug1: identity file /Users/me/.ssh/id_dsa type -1
debug1: identity file /Users/me/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
ssh_exchange_identification: read: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)
到目前为止(根据留言板的建议)我一直在寻找一个主机拒绝文件——但我的机器上没有这样的文件。
$ cat /etc/hosts.deny
cat: /etc/hosts.deny: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我在客户端机器上有管理员访问权限,但在服务器上没有。
Ant*_*hon 27
突然更改可能是服务器sshd配置上的配置文件更改的结果,但您表示没有管理员权限无法检查或更改。如果无法(及时)联系到服务器的管理员,您仍然可以尝试以下操作。
您的日志只显示本地版本字符串,您应该检查sshd服务器和中间机器上运行的版本。
如果这些版本不同(特别是中间机与服务器之间的本地计算机和服务器之间的少),可能有一些不兼容的谈判,这以前也发生在ssh。过去的解决方案是在命令行(ssh -c aes256-ctr等)或您的/etc/ssh/ssh_config.
您应该查看调试信息(从通过中间连接到服务器)以获取适当的值作为-c/ Ciphers、-o HostKeyAlgorithms/HostKeyAlgorithms和-m/MACs命令行响应的参数。ssh_config 更改。
我自己已经有一段时间没有遇到这个问题了,但是当我这样做时,IIRC 足以手动强制 Ciphers 和 HostKeyAlgorithms 设置,之后我可以更新服务器的sshd版本,问题就消失了。
Ski*_*rou 20
您可能已被fail2ban或禁止denyhosts。在这种情况下(以及检查它),如果您不想打扰您的服务器提供商的帮助,您需要从另一个 IP 地址登录您的服务器:例如另一台服务器,或朋友的家庭连接,或wifi 热点,或通过 TOR 使用 SSH。
登录后,检查您的 IP 地址是否确实出现在/etc/hosts.deny(在服务器端)。如果是这样,那么fail2ban或denyhosts一定是罪魁祸首。
有关防止denyhosts连续阻止您的地址的程序,请参阅此问题的答案。要fail2ban查找您的 ipiptables -L --line-number并取消禁止您的 ip iptables -D <chain> <chain number>,您可以查看howtoforge 的详细信息。
您可能需要您的IP地址添加到fail2ban和denyhosts白名单(分别为/etc/fail2ban/jail.conf,线ignoreip,和/var/lib/denyhosts/allowed-hosts,如果需要创建它(但要注意的是,路径可能是你的发行版不同)),以防止问题再次发生。
dev*_*ull 10
在主机服务器上,删除位于此处的 ssh pub.key:~/.ssh/authorized_keys对于您的 Mac。然后,tail -f /var/log/auth.log当您打开另一个终端并再次尝试 ssh 时ssh -v me@server。如果系统提示您输入密码,则说明您的 ssh 密钥有问题。如果您仍然看到“ssh_exchange_identification: read: Connection reset by peer”响应,那么您应该能够在尝试失败后从“/var/log/auth.log”文件中的日志条目中确定问题所在登录。
如果您仍然无法连接,请在此处发布 auth 文件中记录的条目,我将修改我的答案。
小智 5
我遇到了同样的问题。我会成功打开 ssh 会话,但它会在一段时间后重置。当我尝试立即连接增益时,我会收到错误“连接被拒绝”。当我调试会话时,我在连接重置时收到此消息
debug1: client_input_channel_req: channel 0 rtype keepalive@openssh.com reply 1
debug1: client_input_channel_req: channel 0 rtype keepalive@openssh.com reply 1
debug1: client_input_channel_req: channel 0 rtype keepalive@openssh.com reply 1
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i0/0 o0/0 fd 4/5 cfd -1)
debug3: channel 0: close_fds r 4 w 5 e 6 c -1
Read from remote host 10.x.y.z: Connection reset by peer
Connection to 10.x.y.z closed.
debug1: Transferred: stdin 0, stdout 0, stderr 100 bytes in 1029.9 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.1
debug1: Exit status -1
Run Code Online (Sandbox Code Playgroud)
此时我意识到网络上存在 IP 地址冲突。我换了另一个地址,问题解决了
您的日志意味着服务器端断开了连接。要找出原因,您应该查阅服务器端日志,它们应该显示断开连接的原因。您应该几乎总是能够在 /var/log/messages 中找到日志
我可以猜测,由于连接在客户端发送版本号后立即断开,服务器以某种方式威胁客户端不兼容。