SSH使用终端机,云外壳程序或进入Google Cloud VM实例的窗口浏览器不起作用 [英] SSH using terminal, cloud shell, or window browser in to Google Cloud VM instance not working

查看:144
本文介绍了SSH使用终端机,云外壳程序或进入Google Cloud VM实例的窗口浏览器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google云计算的新手.最近,它无法通过SSH进入我的VM实例,以前它可以通过单击SSH按钮并打开新的浏览器窗口来工作.我已经尝试了一些基于互联网搜索的修复程序,主要总结如下:

I am new to google cloud computing. Recently have not been able to SSH into my VM instance, previously it worked by clicking the SSH button and opened a new browser window. I have tried several fixes based on internet searches, mostly summarized below:

当我单击SSH按钮时,它会显示将密钥传输到VM".但永远不会登录并最终超时.

When I click the SSH button, it says "Transferring Keys to the VM" but never logs in and eventually times out.

尝试1:我试图关注另一个线程 Google VM实例未以SSH 和我增加了永久磁盘大小并重置了VM.现在它说无法连接,正在重试...";当我单击SSH按钮并最终超时时.

Attempt 1: I attempted to follow another thread Google VM Instance not opening with SSH and I increased the persistent disk size and reset the VM. Now it says "Could not connect, retrying..." when I click the SSH button and eventually times out.

尝试2:我还尝试通过命令使用Google Cloud Shell通过SSH进入虚拟机

Attempt 2: I also tried SSHing into the VM using Google Cloud Shell using the command

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.

我运行了以下程序,它似乎起作用了

I ran the following and it seems to work

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

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

But when I ran sudo gcloud again it gave me the same empty string error.

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

Attempt 3: I also tried setting up the log in locally using google-cloud-sdk. I followed interactive installing instructions on Using the Google Cloud SDK installer. I tried obtaining ssh key using

gcloud compute project-info describe --project myPROJECT_ID

,然后通过云控制台网站复制到VM的ssh密钥中.我也尝试过

and copied in into the ssh key on for the VM thru the cloud console website. I also tried

sudo gcloud compute config-ssh

这似乎行得通,并给出了以下内容

which seemed to work and gave the following

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命令时,出现以下错误.

When I try running the ssh command I get the following error.

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

我的实例具有启用连接到串行端口"的权限,已激活.

My instance has "enable connecting to serial ports" activated.

我们非常感谢您的协助. 预先谢谢你.

Any assistance is greatly appreciated. Thank you in advance.

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

Update: for the VM instance in question, I clicked on serial port 1 (console) and here are the first 100 lines

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

推荐答案

如果实例正在运行并且可以重新启动它,则可以尝试通过串行控制台登录.此方法与任何防火墙/网络设置无关:)

If your instance is running and you can restart it you may try logging in via serial console. This method is independed from any firewall / network settings :)

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

Just add a user with a password; create a startup script like this (it will create a user and add it to google-sudoers group so you can do everything with this account):

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

然后连接到串行控制台您可以登录.使用控制台窗口或Cloud Shell:gcloud compute connect-to-serial-port instance-name

And then connect to serial console you can log in. Either using console window or cloud shell: gcloud compute connect-to-serial-port instance-name

这将允许您登录.除非您的VM真正崩溃了.

This will allow you to log in. Unless there's something really wront with your VM.

但是-从您的意愿来看-您希望定期进行SSH访问.

But - judging from you desription - you want regular SSH access.

为此,请确保:

  • 您的防火墙规则不会阻止此计算机上的端口22
  • 您在有问题的VM上的防火墙允许端口22上的流量
  • 您的以太网接口已在VM中启动
  • SSH服务器在端口22上侦听(ps aux | grep sshd)
  • you firewall rules don't block port 22 on this machine
  • your firewall on a VM in question allows traffic on port 22
  • your ethernet interface is up in the VM
  • SSH server listens (ps aux | grep sshd) on port 22

然后检查您的VM是否具有外部IP-如果没有,则只能通过具有一个IP的另一个IP或通过Cloud Shell(当然还有如上所述的串行控制台)连接到您的VM.

Then check if your VM has external IP - if not you will be only able to connect to your VM via another that has one, or via cloud shell (and of course serial console as described above).

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

However - since you got this Permission denied (publickey) message that means that for some reason your SSH keys don't work (corrupted, deleted etc). When you log in with serial console check if they're there. If not you can add them manually.

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

----------- UPDATE ------------

查看此行:7月2日12:19:02实例google_accounts_daemon [822]:gpasswd:/etc/group.####:设备上没有剩余空间-它表示您的VM用完了磁盘空间.停止您的VM,尝试首先使用gcloud计算磁盘调整mydiskname --size = 100GB --zone = us-central1-a大小的大小来重新调整VM磁盘的大小,然后启动它.启动后,VM的分区将被调整大小. –

Look at this line: Jul 2 12:19:02 INSTANCE google_accounts_daemon[822]: gpasswd: /etc/group.####: No space left on device - it says that your VM ran out of disk space. Stop your VM, try resizing your VM's disk first with gcloud compute disks resize mydiskname --size=100GB --zone=us-central1-a and start it. After the start VM's partition will be resized. –

这篇关于SSH使用终端机,云外壳程序或进入Google Cloud VM实例的窗口浏览器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆