重启后无法通过 SSH 进入 ec2

重启后无法通过 SSH 进入 ec2

我希望这是发布此内容的正确地方。今天,我在重启后被锁定在了我的 ec2 之外。当我尝试 ssh 时,它显示的内容如下:

OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to xx.xx.xx.xx [xx.xx.xx.xx] port 22.
debug1: connect to address xx.xx.xx.xx port 22: Connection refused
ssh: connect to host xx.xx.xx.xx port 22: Connection refused

我已回答过以下问题:

https://stackoverflow.com/questions/14026148/running-ec2-instance-suddenly-refuses-ssh-connection

Amazon EC2-重启后无 SSH,连接被拒绝

https://www.youtube.com/watch?v=_P29ZHu_feU

我已经尝试过分离卷以修复 sshd_config,但这似乎无法解决问题。幸运的是,今天做任何事情之前我都有 AMI,我重新启动了实例,它运行良好。但是,当我运行并yum update重新启动实例时,我又被锁定了。

这些是今天更新的内容:

Dependencies Resolved

================================================================================================================================================================
 Package                            Arch                   Version                                      Repository                                         Size
================================================================================================================================================================
Installing:
 kernel                             x86_64                 2.6.32-642.3.1.el6                           rhui-REGION-rhel-server-releases                   32 M
Updating:
 autofs                             x86_64                 1:5.0.5-123.el6_8                            rhui-REGION-rhel-server-releases                  721 k
 elasticsearch                      noarch                 2.3.5-1                                      elasticsearch-2.x                                  26 M
 httpd                              x86_64                 2.2.15-54.el6_8                              rhui-REGION-rhel-server-releases                  833 k
 httpd-tools                        x86_64                 2.2.15-54.el6_8                              rhui-REGION-rhel-server-releases                   78 k
 initscripts                        x86_64                 9.03.53-1.el6_8.1                            rhui-REGION-rhel-server-releases                  947 k
 java-1.7.0-openjdk                 x86_64                 1:1.7.0.111-2.6.7.2.el6_8                    rhui-REGION-rhel-server-releases                   26 M
 kernel-firmware                    noarch                 2.6.32-642.3.1.el6                           rhui-REGION-rhel-server-releases                   28 M
 kernel-headers                     x86_64                 2.6.32-642.3.1.el6                           rhui-REGION-rhel-server-releases                  4.4 M
 libcgroup                          x86_64                 0.40.rc1-18.el6_8                            rhui-REGION-rhel-server-releases                  130 k
 libipa_hbac                        x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  112 k
 libsss_idmap                       x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  118 k
 libtiff                            x86_64                 3.9.4-18.el6_8                               rhui-REGION-rhel-server-releases                  345 k
 libxml2                            x86_64                 2.7.6-21.el6_8.1                             rhui-REGION-rhel-server-releases                  805 k
 libxml2-python                     x86_64                 2.7.6-21.el6_8.1                             rhui-REGION-rhel-server-releases                  325 k
 mdadm                              x86_64                 3.3.4-1.el6_8.5                              rhui-REGION-rhel-server-releases                  348 k
 mod_ssl                            x86_64                 1:2.2.15-54.el6_8                            rhui-REGION-rhel-server-releases                   97 k
 nfs-utils                          x86_64                 1:1.2.3-70.el6_8.1                           rhui-REGION-rhel-server-releases                  335 k
 nss-softokn                        x86_64                 3.14.3-23.3.el6_8                            rhui-REGION-rhel-server-releases                  262 k
 nss-softokn-freebl                 x86_64                 3.14.3-23.3.el6_8                            rhui-REGION-rhel-server-releases                  168 k
 perf                               x86_64                 2.6.32-642.3.1.el6                           rhui-REGION-rhel-server-releases                  4.6 M
 php56w                             x86_64                 5.6.24-1.w6                                  webtatic                                          2.7 M
 php56w-cli                         x86_64                 5.6.24-1.w6                                  webtatic                                          2.6 M
 php56w-common                      x86_64                 5.6.24-1.w6                                  webtatic                                          1.2 M
 php56w-gd                          x86_64                 5.6.24-1.w6                                  webtatic                                          144 k
 php56w-mbstring                    x86_64                 5.6.24-1.w6                                  webtatic                                          944 k
 php56w-mcrypt                      x86_64                 5.6.24-1.w6                                  webtatic                                           25 k
 php56w-mysql                       x86_64                 5.6.24-1.w6                                  webtatic                                          111 k
 php56w-pdo                         x86_64                 5.6.24-1.w6                                  webtatic                                           94 k
 php56w-process                     x86_64                 5.6.24-1.w6                                  webtatic                                           35 k
 php56w-tidy                        x86_64                 5.6.24-1.w6                                  webtatic                                           29 k
 php56w-xml                         x86_64                 5.6.24-1.w6                                  webtatic                                          148 k
 python-libipa_hbac                 x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  107 k
 python-sssdconfig                  noarch                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  141 k
 samba4-libs                        x86_64                 4.2.10-7.el6_8                               rhui-REGION-rhel-server-releases                  4.4 M
 sssd                               x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  108 k
 sssd-ad                            x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  211 k
 sssd-client                        x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  164 k
 sssd-common                        x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  1.1 M
 sssd-common-pac                    x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  147 k
 sssd-ipa                           x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  277 k
 sssd-krb5                          x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  143 k
 sssd-krb5-common                   x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  163 k
 sssd-ldap                          x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  209 k
 sssd-proxy                         x86_64                 1.13.3-22.el6_8.4                            rhui-REGION-rhel-server-releases                  137 k
 tar                                x86_64                 2:1.23-15.el6_8                              rhui-REGION-rhel-server-releases                  810 k
 tzdata                             noarch                 2016f-1.el6                                  rhui-REGION-rhel-server-releases                  452 k
 tzdata-java                        noarch                 2016f-1.el6                                  rhui-REGION-rhel-server-releases                  180 k
 yum                                noarch                 3.2.29-75.el6_8                              rhui-REGION-rhel-server-releases                  1.0 M
Removing:
 kernel                             x86_64                 2.6.32-573.18.1.el6                          @rhui-REGION-rhel-server-releases                 126 M

Transaction Summary
================================================================================================================================================================
Install       1 Package(s)
Upgrade      48 Package(s)
Remove        1 Package(s)

Total download size: 144 M

我的问题是:

  1. 如何确保重启后 ssh 已启动?我被锁定在服务器之外。
  2. 我高度怀疑其中一个包有错误,但我不知道是哪个。有什么方法可以查明错误原因吗?

答案1

错误connection refused可能意味着sshd服务未启动,因此没有按应有的方式监听端口 22。

在重启之前,更新软件包之后,请检查OpenSSH仍在运行telnet localhost 22telnetyum install telnet键入OpenSSH横幅,则表示正在运行,请telnet键入^](control-]) 退出。如果没有,则表示更新过程失败。请尝试以下操作来查看更新的状态sshd服务:

非 systemd(CentOS 7 之前)

# chkconfig --列表 sshd

如果您看到它off,请使用以下命令启用它:

# chkconfig sshd 开启

然后启动它:

# 启动 sshd 服务

重试telnet。如果仍然没有响应,请检查/var/log/messages并找出拒绝启动的原因。

使用 systemd(CentOS 7 及更高版本):

#systemctl 状态 sshd -l

此命令应告诉您上次尝试启动时发生了什么sshd。如果它显示sshd不是enabled,则意味着它不会在启动时启动,请使用以下命令启用它:

#systemctl 启用 sshd

如果没有响应就启动它:

#systemctl 启动 sshd

再次检查启动过程如何systemctl status sshd,过程中发生的错误应该显示在控制台中。

至于有关调试yum更新过程的问题,您可能希望将值debuglevel从 2(默认值)上升到 10(更高值)/etc/yum.conf

相关内容