当我 ping 我的服务器时,它响应:
Pinging 192.168.2.222 with 32 bytes of data:
Reply from 192.168.2.222: bytes=32 time<1ms TTL=64
Reply from 192.168.2.222: bytes=32 time<1ms TTL=64
Reply from 192.168.2.222: bytes=32 time<1ms TTL=64
Reply from 192.168.2.222: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.2.222:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
当我使用Xshell连接服务器时,它有响应但停在了下面这一行:
Connecting to 192.168.2.222:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
服务器上运行着一个 Rstudio 服务器,192.168.2.222:8787 也没有响应(一直处于连接状态)。然后我尝试使用 debug 进行 ssh,它也停在最后一行:
>ssh -vvv 192.168.2.222
OpenSSH_7.1p2, OpenSSL 1.0.1g 7 Apr 2014
debug1: Reading configuration data /etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.2.222 [192.168.2.222] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mobaxterm/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
然后我尝试使用以下命令行以其他方式诊断服务器:
>nc -v -w 1 192.168.2.222 22
Connection to 192.168.2.222 22 port [tcp/ssh] succeeded!
我仍然搞不清楚到底发生了什么!当我进入服务器机房时,服务器黑屏,没有响应任何消息。手动重启计算机后,我可以用 ssh 登录计算机。但几个小时后,问题又出现了!我真的不知道问题出在哪里,我只是个学生,对 Linux 服务器不太了解。服务器运行的是 CentOS 6.5。
答案1
ssh 协议/包可能存在问题尝试重新安装或升级 open-ssh 服务器包并重新生成密钥
如何重新生成新的 ssh 服务器密钥
这是一个不寻常的话题,因为大多数发行版在安装 OpenSSH 服务器包时会为您创建这些密钥。但有时能够生成新的服务器密钥可能会很有用,当我复制包含已安装 ssh 包的虚拟专用服务器时,就会发生这种情况。OpenSSH 需要不同的密钥,具体取决于您使用的是 SSH1 还是 SSH2 协议。所有密钥均由 ssh-keygen 生成,该密钥应在 ssh 包中随系统提供。接收方式与生成您自己的密钥几乎相同,只是您应该使用空密码。默认密钥长度也合适(rsa 为 2048 位,dsa 为 1024 位)
SSH1 协议对于 SSH1 协议,您需要生成一个 rsa1 密钥,如下所示:ssh-keygen -q -f /etc/ssh/ssh_host_key -N '' -t rsa1
SSH2 协议对于 SSH2 协议,您需要两个密钥,一个 RSA 密钥和一个 DSA 密钥,生成方式如下:
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
自 2011 年 1 月起,OpenSSH 还支持 ECDSA 密钥,您可以使用以下命令生成一个新密钥:ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521