繁体   English   中英

SSH 使用终端、云 shell 或 window 浏览器进入 Google Cloud VM 实例不工作

[英]SSH using terminal, cloud shell, or window browser in to Google Cloud VM instance not working

我是谷歌云计算的新手。 最近无法将 SSH 插入我的 VM 实例,之前它通过单击 SSH 按钮并打开一个新的浏览器 window 来工作。 我已经尝试了几个基于互联网搜索的修复,主要总结如下:

当我单击 SSH 按钮时,它显示“将密钥传输到 VM”但从未登录并最终超时。

尝试 1:我尝试关注另一个线程Google VM Instance not opening with SSH ,我增加了永久磁盘大小并重置了 VM。 现在,当我单击 SSH 按钮并最终超时时,它显示“无法连接,正在重试...”。

尝试 2:我还尝试使用 Google Cloud Shell 使用命令通过 SSH 连接到 VM

gcloud beta compute ssh --zone "myZONE" "VM_instance_name" --project "PROJECT_ID"

并得到以下错误

Permission denied (publickey).
ERROR: (gcloud.beta.compute.ssh) [/usr/bin/ssh] exited with return code [255].

我使用创建了新密钥

sudo gcloud compute config-ssh

它给了我这个错误

ERROR: (gcloud.compute.config-ssh) The project property is set to the empty string, which is invalid.

我跑了以下,它似乎工作

gcloud config set project myPROJECT_ID
Updated property [core/project].

但是当我再次运行 sudo gcloud 时,它给了我同样的空字符串错误。

尝试 3:我还尝试使用 google-cloud-sdk 在本地设置登录。 我按照使用 Google Cloud SDK 安装程序的交互式安装说明进行操作。 我尝试使用获取 ssh 密钥

gcloud compute project-info describe --project myPROJECT_ID

并通过云控制台网站复制到 VM 上的 ssh 密钥中。 我也试过

sudo gcloud compute config-ssh

这似乎有效并给出了以下内容

Updating project ssh metadata...⠼Updated [https://...].                                                 
Updating project ssh metadata...done.                                                                                                             
You should now be able to use ssh/scp with your instances.
For example, try running:

  $ ssh VMinstance.myzone.PROJECT_ID

当我尝试运行 ssh 命令时,出现以下错误。

ssh: Could not resolve hostname VMinstance.myzone.PROJECT_ID: nodename nor servname provided, or not known

我的实例已激活“启用连接到串行端口”。

非常感谢任何帮助。 先感谢您。

更新:对于有问题的 VM 实例,我单击了serial port 1 (console) ,这是前 100 行

serialport: Connected to PROJECT_ID.Zone.VMInstance port 1 (session ID: ##..., active connections: 1).
Jul  2 12:19:02 INSTANCE google-accounts: INFO Removing user root.
Jul  2 12:19:02 INSTANCE google-accounts: INFO Removing user root from the Google sudoers group.
[1##.##8] google_accounts_daemon[822]: Removing user root from group google-sudoers
Jul  2 12:19:02 INSTANCE google_accounts_daemon[822]: Removing user root from group google-sudoers
[1##.##0] google_accounts_daemon[822]: gpasswd: /etc/group.####: No space left on device
Jul  2 12:19:02 INSTANCE google_accounts_daemon[822]: gpasswd: /etc/group.####: No space left on device
[1##.##6] google_accounts_daemon[822]: gpasswd: cannot lock /etc/group; try again later.
Jul  2 12:19:02 INSTANCE google_accounts_daemon[822]: gpasswd: cannot lock /etc/group; try again later.
Jul  2 12:19:02 INSTANCE google-accounts: WARNING Could not update user root. Command '['gpasswd', '-d', 'root', 'google-sudoers']' returned non-zero exit status 1..
Jul  2 12:19:02 INSTANCE google-accounts: ERROR Exception calling the response handler. [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/'].#012Traceback (most recent call last):#012  File "/usr/lib/python3/dist-packages/google_compute_engine/metadata_watcher.py", line 200, in WatchMetadata#012    handler(response)#012  File "/usr/lib/python3/dist-packages/google_compute_engine/accounts/accounts_daemon.py", line 285, in HandleAccounts#012    self.utils.SetConfiguredUsers(desired_users.keys())#012  File "/usr/lib/python3/dist-packages/google_compute_engine/accounts/accounts_utils.py", line 318, in SetConfiguredUsers#012    mode='w', prefix=prefix, delete=True) as updated_users:#012  File "/usr/lib/python3.6/tempfile.py", line 681, in NamedTemporaryFile#012    prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir)#012  File "/usr/lib/python3.6/tempfile.py", line 269, in _sanitize_params#012    dir = gettempdir()#012  File "/usr/lib/python3.6/tempfile.py", line 437, in gettempdir#012    tempdir = _get_default_tempdir()#012  File "/usr/lib/python3.6/tempfile.py", line 372, in _get_default_tempdir#012    dirlist)#012FileNotFoundError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/']
Jul  2 12:19:41 INSTANCE systemd[1]: snapd.service: Start operation timed out. Terminating.
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: sed: couldn't flush /etc/ssh/sedYpckqQ: No space left on device
[1##.##1] google_accounts_daemon[822]: sed: couldn't flush /etc/ssh/sedYpckqQ: No space left on device
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedeXXx0O: No space left on device
[1##.##4] google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedeXXx0O: No space left on device
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sed27Z7HO: No space left on device
[1##.##2] google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sed27Z7HO: No space left on device
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sed3bBBFO: No space left on device
[1##.##6] google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sed3bBBFO: No space left on device
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedUKduxP: No space left on device
[1##.##3] google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedUKduxP: No space left on device
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedhtixlP: No space left on device
[1##.##0] google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedhtixlP: No space left on device
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedy6zVAS: No space left on device
[1##.##9] google_accounts_daemon[822]: sed: couldn't flush /etc/pam.d/sedy6zVAS: No space left on device
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: Restarting optional services.
[1##.##7] google_accounts_daemon[822]: Restarting optional services.
Jul  2 12:20:03 INSTANCE systemd[1]: Stopping Login Service...
Jul  2 12:20:03 INSTANCE systemd[1]: Stopped Login Service.
Jul  2 12:20:03 INSTANCE systemd[1]: Starting Login Service...
Jul  2 12:20:03 INSTANCE systemd[1]: Started Login Service.
Jul  2 12:20:03 INSTANCE systemd[1]: Stopping Regular background program processing daemon...
Jul  2 12:20:03 INSTANCE systemd[1]: Stopped Regular background program processing daemon.
Jul  2 12:20:03 INSTANCE systemd[1]: Started Regular background program processing daemon.
Jul  2 12:20:03 INSTANCE google_accounts_daemon[822]: Restarting SSHD
[1##.##5] google_accounts_daemon[822]: Restarting SSHD
Jul  2 12:20:03 INSTANCE systemd[1]: Stopping OpenBSD Secure Shell server...
Jul  2 12:20:03 INSTANCE systemd[1]: Stopped OpenBSD Secure Shell server.
Jul  2 12:20:03 INSTANCE systemd[1]: Starting Google Compute Engine Instance Setup...
Jul  2 12:20:03 INSTANCE instance-setup: WARNING [Errno 28] No space left on device
Jul  2 12:20:03 INSTANCE instance-setup: INFO Running google_set_multiqueue.
Jul  2 12:20:03 INSTANCE instance-setup: INFO Setting /proc/irq/31/smp_affinity_list to 0 for device virtio1.
Jul  2 12:20:03 INSTANCE instance-setup: INFO /proc/irq/31/smp_affinity_list: real affinity 0
Jul  2 12:20:03 INSTANCE instance-setup: INFO Setting /proc/irq/32/smp_affinity_list to 0 for device virtio1.
Jul  2 12:20:03 INSTANCE instance-setup: INFO /proc/irq/32/smp_affinity_list: real affinity 0
Jul  2 12:20:03 INSTANCE instance-setup: INFO /usr/bin/google_set_multiqueue: line 139: echo: write error: No such file
 or directory
Jul  2 12:20:03 INSTANCE instance-setup: INFO cat: /sys/class/net/ens4/queues/tx-0/xps_cpus: No such file or directory
Jul  2 12:20:03 INSTANCE instance-setup: INFO Queue 0 XPS=/sys/class/net/ens4/queues/tx-0/xps_cpus for
Jul  2 12:20:03 INSTANCE instance-setup: WARNING [Errno 28] No space left on device
Jul  2 12:20:03 INSTANCE systemd[1]: Started Google Compute Engine Instance Setup.
Jul  2 12:20:03 INSTANCE systemd[1]: Starting OpenBSD Secure Shell server...
Jul  2 12:20:03 INSTANCE systemd[1]: Started OpenBSD Secure Shell server.
Jul  2 12:20:03 INSTANCE systemd[1]: Stopping OpenBSD Secure Shell server...
Jul  2 12:20:03 INSTANCE systemd[1]: Stopped OpenBSD Secure Shell server.
Jul  2 12:20:03 INSTANCE systemd[1]: Starting Google Compute Engine Instance Setup...
Jul  2 12:20:04 INSTANCE instance-setup: WARNING [Errno 28] No space left on device
Jul  2 12:20:04 INSTANCE instance-setup: INFO Running google_set_multiqueue.
Jul  2 12:20:04 INSTANCE instance-setup: INFO Setting /proc/irq/31/smp_affinity_list to 0 for device virtio1.
Jul  2 12:20:04 INSTANCE instance-setup: INFO /proc/irq/31/smp_affinity_list: real affinity 0
Jul  2 12:20:04 INSTANCE instance-setup: INFO Setting /proc/irq/32/smp_affinity_list to 0 for device virtio1.
Jul  2 12:20:04 INSTANCE instance-setup: INFO /proc/irq/32/smp_affinity_list: real affinity 0
Jul  2 12:20:04 INSTANCE instance-setup: INFO /usr/bin/google_set_multiqueue: line 139: echo: write error: No such file or directory

如果您的实例正在运行并且您可以重新启动它,您可以尝试通过串行控制台登录。 此方法独立于任何防火墙/网络设置:)

只需添加一个带密码的用户; 创建一个像这样的启动脚本(它将创建一个用户并将其添加到google-sudoers组,以便您可以使用此帐户执行所有操作):

#! /bin/bash
adduser username
echo 'sudouser:userspass' | chpasswd
usermod -aG google-sudoers sudouser

然后连接到串行控制台,您可以登录。使用控制台 window 或云 shell: gcloud compute connect-to-serial-port instance-name

这将允许您登录 除非你的虚拟机真的有问题。

但是 - 从你的描述来看 -你想要常规的 SSH 访问

为此,请确保:

  • 您的防火墙规则不会阻止此计算机上的端口 22
  • 有问题的 VM 上的防火墙允许端口 22 上的流量
  • 您的以太网接口已在 VM 中启动
  • SSH 服务器在端口 22 上侦听ps aux | grep sshd

然后检查您的虚拟机是否有外部 IP - 如果没有,您将只能通过另一个有一个的虚拟机或通过云 shell(当然还有如上所述的串行控制台)连接到您的虚拟机。

但是 - 由于您收到此Permission denied (publickey)消息,这意味着由于某种原因您的 SSH 密钥不起作用(损坏、删除等)。 当您使用串行控制台登录时, 检查它们是否在那里 如果没有,您可以手动添加它们

- - - - - - 更新 - - - - - -

看看这一行: Jul 2 12:19:02 INSTANCE google_accounts_daemon[822]: gpasswd: /etc/group.####: No space left on device - 它表示您的 VM 磁盘空间不足。 停止您的虚拟机,尝试先使用 gcloud compute disks resize mydiskname --size=100GB --zone=us-central1-a 调整虚拟机磁盘的大小并启动它。 启动后,VM 的分区将被调整大小。

暂无
暂无

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

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