繁体   English   中英

为什么 Google Cloud Compute Engine 实例在重启后拒绝 ssh 连接?

[英]Why Google Cloud Compute Engine instance gives ssh connection refused after restart?

我停止并重新启动了一个 ubuntu 14.04 Google Cloud Compute Engine 实例,现在我的 ssh 连接被拒绝:

ssh: connect to host 146.148.114.98 port 22: Connection refused

这已经发生过一次,我认为机器有问题,我删除它并重新创建它并再次开始工作。 我不想每次都重新创建实例。 google cloud 的 ssh 故障排除页面比较乱。 我的防火墙规则似乎没问题。 有人对此有解决方案吗?

NAME                    NETWORK  SRC_RANGES    RULES                         SRC_TAGS  TARGET_TAGS
default-allow-http      default  0.0.0.0/0     tcp:80                                  http-server
default-allow-https     default  0.0.0.0/0     tcp:443                                 https-server
default-allow-icmp      default  0.0.0.0/0     icmp
default-allow-internal  default  10.128.0.0/9  tcp:0-65535,udp:0-65535,icmp
default-allow-rdp       default  0.0.0.0/0     tcp:3389
default-allow-ssh       default  0.0.0.0/0     tcp:22

这是输出: ps aux | grep ssh ps aux | grep ssh

root        29  0.0  0.4  55184  2860 ?        Ss   11:26   0:00 /usr/sbin/sshd -p 22 -o AuthorizedKeysCommand=/google/devshell/authorized_keys.sh -o Author
izedKeysCommandUser=root
root       183  0.0  0.9  82692  5940 ?        Ss   11:26   0:00 sshd: fbeshox [priv]                                                                       

fbeshox    218  0.0  0.7  82692  4424 ?        S    11:26   0:00 sshd: fbeshox@pts/0                                                                        

fbeshox    522  0.0  0.3  12728  2200 pts/1    S+   12:12   0:00 grep ssh

这里是 ssh 连接尝试的详细结果。

ssh -i .ssh/keyname username@130.211.53.51 -vvv
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/xxxx/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 130.211.53.51 [130.211.53.51] port 22.
debug1: connect to address 130.211.53.51 port 22: Connection refused
ssh: connect to host 130.211.53.51 port 22: Connection refused

Ubuntu 上默认安装的安全工具sshguard可能会干扰您的连接。 基本上 sshguard 可能错误地认为您的 IP 地址正在“攻击”您的实例并阻止了该 IP。

如果您可以从其他位置登录,例如 Cloud Console 提供的 Web SSH,请尝试使用sudo iptables -S查看 sshguard 创建的实例上是否有任何防火墙规则(不同于 GCE 防火墙)。 如果是这样,请尝试禁用 sshguard 或将您的 IP 地址添加到白名单 ( http://www.sshguard.net/docs/whitelist/ )。

我知道这是一个老问题,但今天我遇到了类似的问题,问题很简单——重启后实例的 IP 发生了变化——所以我不得不相应地更新 ssh 字符串

在您更改默认区域或区域后,通常会发生此问题。 然后,您必须通过 sudo gcloud compute config-ssh 更新元数据中的 ssh 密钥

您还可以在 Compute Engine | 下查看 Web 界面中的更改。 元数据 | SSH 密钥。

尝试使用不同的用户名通过 SSH 连接到实例。Google Compute 有时有点不稳定。 尝试使用 Compute Engine 中的 VM 实例页面通过 SSH 连接到实例。 如果 SSH 花费太多时间并拒绝连接,则在 SSH 中使用不同的用户名登录。 您可以使用 SSH 窗口右上角的设置图标以不同的名称登录。 如果这些都不顺利,我会建议你重新创建一个实例,因为我的经验也是 Google Compute Engine 实例在 SSH 可访问性方面不稳定并且容易产生问题。最好是使用 putty 作为 SSH 进入 Compute Engine 的客户端,而不是 Google 提供的 SSH 终端。 让我知道这是否对您有帮助:)

我知道当机器停止并安装该磁盘时,从控制台分离磁盘后出现了我的问题。 首先卸载磁盘,然后将其分离。 再也没有看到这个问题。

还要确保您没有递归地修改/etc文件夹的权限。

例如:

chmod -R 775 /etc

这将阻止您重新登录到 VM,即使是从 Web 控制台和 gcloud cli 也是如此。

相反,在更精细的级别上修改权限,例如/etc/nginx等。

我遇到了同样的问题,并通过首先通过浏览器 SSH (来自“VM 实例”Web 概述)连接到 VM 来解决它,这也失败了,然后选择提供的选项,即在没有 Cloud Identity-Aware Proxy的情况下重试有效。

之后所有 SSH 连接再次工作(在浏览器和本地 shell 中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM