在 aws ec2 实例重启后无法 ssh“连接超时”

在 aws ec2 实例重启后无法 ssh“连接超时”

重新启动 aws ec2 实例后,我无法再通过 ssh 进入它,Windows 上的 putty 告诉我“网络错误:连接超时”,并且在 Linux 机器的命令行上也会发生同样的情况。

该机器正在运行 Ubuntu 16.04。该实例附加有一个弹性 IP(因此不会因 IP 更改而产生任何重启问题)。

实例似乎按预期运行(apache 网站运行良好)但我无法再连接到实例 shell。

查看系统日志,我注意到很多行包含“FAILED”字样:

[[0;1;31mFAILED[0m] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.

以及这些的出现:

[[0;1;31mFAILED[0m] Failed to start Service for snap ap...azon-ssm-agent.amazon-ssm-agent.
See 'systemctl status snap.amazon-ssm-a...mazon-ssm-agent.service' for details.

我配置了 ec2 实例用户数据以获取 ssh 的输出:

service sshd status > /var/www/html/XXXX/sshlog.txt

日志输出是这样的:

â— ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: failed (Result: start-limit-hit) since Wed 2019-05-15 11:03:05 UTC; 1s ago
  Process: 1454 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255)

May 15 11:03:05 ip-172-31-4-244 systemd[1]: Failed to start OpenBSD Secure Shell server.
May 15 11:03:05 ip-172-31-4-244 systemd[1]: ssh.service: Unit entered failed state.
May 15 11:03:05 ip-172-31-4-244 systemd[1]: ssh.service: Failed with result 'start-limit-hit'.
May 15 11:03:06 ip-172-31-4-244 systemd[1]: Stopped OpenBSD Secure Shell server.
May 15 11:03:06 ip-172-31-4-244 systemd[1]: ssh.service: Start request repeated too quickly.
May 15 11:03:06 ip-172-31-4-244 systemd[1]: Failed to start OpenBSD Secure Shell server.
May 15 11:03:06 ip-172-31-4-244 systemd[1]: ssh.service: Failed with result 'start-limit-hit'.
May 15 11:03:06 ip-172-31-4-244 systemd[1]: ssh.service: Start request repeated too quickly.
May 15 11:03:06 ip-172-31-4-244 systemd[1]: Failed to start OpenBSD Secure Shell server.
May 15 11:03:06 ip-172-31-4-244 systemd[1]: ssh.service: Failed with result 'start-limit-hit'.

有人能帮我调查这个问题吗?

提前致谢!

答案1

我觉得 ssh 服务器可能存在配置问题。您看到的日志条目只是 ssh 服务器抱怨启动过于频繁。更有意义的错误消息可能在日志中更靠前的某个地方。

我建议创建一个新的临时实例,然后安装实例的卷(关闭实例后,首先需要将其分离),并仔细查看日志。然后,我会尝试用临时实例中的文件替换 /etc/ssh/sshd_config 文件(首先复制原始文件)。然后关闭临时实例,分离卷,将其重新连接到第一个实例,然后启动它。这可能会解决您的问题。也可能不会——但这是首先要尝试的事情。

相关内容