简体   繁体   English

无法通过云 ssh shell 终端[谷歌云平台]

[英]Unable to ssh via cloud shell terminal [google cloud platform]

It's a couple of days I'm trying to login and use my VM via SSH cloud shell as I always did with no issues.几天后,我试图通过 SSH 云 shell 登录并使用我的虚拟机,就像我一直做的那样,没有任何问题。

here the error I got这是我得到的错误

Transferring SSH keys to the VM. The key transfer to project metadata is taking an unusually long time. Transferring instead to instance metadata may be faster, but will transfer the keys only to this VM. If you wish to SSH into other VMs from this VM, you will need to transfer the keys accordingly. Click here to transfer the key to instance metadata. Note that this setting is persistent and needs to be disabled in the Instance Details page once enabled. You can drastically improve your key transfer times by migrating to OS Login.

After digging a bit I found this more detailed error in my connection log:经过一番挖掘后,我在连接日志中发现了这个更详细的错误:

Mar 5 13:46:02 ubuntu-tw 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

I tried to increase my VM disk space, but the result is the same.我试图增加我的虚拟机磁盘空间,但结果是一样的。

At this point I think the easy way is to simply download my scripts there, but how to access the files?在这一点上,我认为简单的方法是简单地在那里下载我的脚本,但是如何访问这些文件呢?

If you want to change or increase the size of your disk first you must create a new instance and recreate the boot disk from a snapshot to resize it.you can do this with this link Recovering an inaccessible instance or a full boot disk如果您想首先更改或增加磁盘的大小,您必须创建一个新实例并从快照重新创建引导磁盘以调整其大小。您可以通过此链接恢复无法访问的实例或完整的引导磁盘来执行此操作

  1. Go to the VM instances creation page Go 到VM 实例创建页面

Google Cloud -> Compute Engine ->VM Instances谷歌云 -> 计算引擎 -> 虚拟机实例

a.一个。 Click the instance name to open the VM instance details page.单击实例名称,打开虚拟机实例详情页面。

b.湾。 Click Stop单击停止

c. c。 In the Boot disk section, note the boot disk's size and name.引导磁盘部分,记下引导磁盘的大小和名称。

  1. In the Google Cloud Console, go to the Snapshots creation page.在 Google Cloud Console 中,go 到 快照创建页面。

Google Cloud -> Compute Engine -> Storage -> Snapshots谷歌云 -> 计算引擎 -> 存储 -> 快照

a.一个。 Enter a snapshot Name .输入快照名称

b.湾。 Select the boot disk from the Source disk drop-down list. Select源磁盘下拉列表中的引导磁盘。

c. c。 Click Create .单击创建

  1. Go to the VM instances creation page. Go 到VM 实例创建页面。

Google Cloud -> Compute Engine ->VM Instances谷歌云 -> 计算引擎 -> 虚拟机实例

  1. Enter the instance details.输入实例详细信息。

  2. Create a new boot disk from the snapshot of the old boot disk.从旧启动磁盘的快照创建一个新的启动磁盘。

a.一个。 Under Boot disk , select Change .引导盘下, select更改

b.湾。 Select Snapshots . Select快照

c. c。 Select the snapshot of the old boot disk from the Snapshot drop-down list. Select快照下拉列表中旧启动磁盘的快照

d. d。 Select the Boot disk type . Select引导盘类型

e. e. Enter the new size for the disk.输入磁盘的新大小。

f. F。 Click Select to confirm your disk options.单击Select以确认您的磁盘选项。

  1. Click Create .单击创建

  2. Mount and format the disk.挂载并格式化磁盘。

Another option is attach the disk to a VM: Formatting and mounting a zonal persistent disk另一种选择是将磁盘附加到 VM: 格式化和安装区域永久性磁盘

Also I recommended you to do a snapshot or a clone of your disk to avoid the risk of losing the data.我还建议您对磁盘进行快照或克隆,以避免丢失数据的风险。

to do this go to disks执行此 go 到磁盘

Google Cloud -> Compute Engine ->Disks谷歌云 -> 计算引擎 -> 磁盘

select your disk and then in the actions toolbar select the option Create Snapshot or Clone disk to do this. select 您的磁盘,然后在操作工具栏中 select 选项创建快照克隆磁盘执行此操作。

If you only need to resize your disk you can do it in this part: Resizing a zonal persistent disk如果您只需要调整磁盘大小,您可以在此部分中进行: 调整区域永久性磁盘的大小

go to your disks page go 到您的磁盘页面

Google Cloud -> Compute Engine ->Disks谷歌云 -> 计算引擎 -> 磁盘

  1. Click on your disk name单击您的磁盘名称

  2. Click on the edit button点击编辑按钮

  3. in Properties you can change the size of your disk属性中,您可以更改磁盘的大小

  4. Click on Save button点击保存按钮

Then you need to restart your VM and your changes there will be applied然后您需要重新启动您的虚拟机,您的更改将被应用

Edit 03082021编辑 03082021

found this, to access via serial console: Interacting with the serial console找到这个,通过串行控制台访问: Interacting with the serial console

Edit 03092021编辑 03092021

for add or remove the SSH keys you need to follow this next steps: Adding or removing project-wide public SSH keys要添加或删除 SSH 密钥,您需要执行以下步骤: 添加或删除项目范围的公共 SSH 密钥

To add or remove project-wide public SSH keys from the Cloud Console:如需从 Cloud Console 添加或移除项目范围的公共 SSH 密钥,请执行以下操作:

  1. In the Google Cloud Console, go to the metadata page for your project.在 Google Cloud Console 中,将 go 转到您项目的元数据页面。 Go to the Metadata page Go 到元数据页面

  2. Under SSH Keys , click Edit .SSH 密钥下,单击编辑

  3. Modify the project-wide public SSH keys:修改项目范围的公共 SSH 密钥:

To add a public SSH key, click Add item .要添加公共 SSH 密钥,请单击Add item A text box opens.将打开一个文本框。

Copy and paste the contents of your public SSH key file into the text box.公共 SSH 密钥文件的内容复制并粘贴到文本框中。

Repeat this process for each public SSH key that you want to add.对要添加的每个公共 SSH 密钥重复此过程。

To remove a public SSH key, click the removal button next to it:要删除公共 SSH 密钥,请单击其旁边的删除按钮: 替代文字

Repeat this process for each public SSH key that you want to remove.对要删除的每个公共 SSH 密钥重复此过程。

  1. When you have finished editing the SSH keys, click Save .完成 SSH 密钥的编辑后,单击保存

and here you create a new SSH key Creating a new SSH key在这里您创建一个新的 SSH 密钥创建一个新的 SSH 密钥

Open a terminal on your workstation在工作站上打开终端

run this command:运行这个命令:

ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]

Replace the following:替换以下内容:

[KEY_FILENAME] : the name that you want to use for your SSH key files. [KEY_FILENAME] :您要用于 SSH 密钥文件的名称。 For example, a filename of my-ssh-key generates a private key file named my-ssh-key and a public key file named my-ssh例如,文件名my-ssh-key生成一个名为my-ssh-key的私钥文件和一个名为my-ssh的公钥文件

[USERNAME] : the name of the user connecting to the VM. [USERNAME] : 连接到虚拟机的用户名。 For example, youremail@gmail.com例如, youremail@gmail.com

here is an example:这是一个例子:

ssh-keygen -t rsa -f ~/.ssh/my-new-ssh-key -C myficticialmail@gmail.com

The next is choose a passphrase that you remember and confirm the passphrase接下来是选择您记住的密码并确认密码

  1. Restrict access to your private key so that only you can read it and nobody can write to it限制对您的私钥的访问,以便只有您可以读取它,而没有人可以写入它

    chmod 400 ~/.ssh/[KEY_FILENAME]

where [KEY_FILENAME] is the name that you used for your SSH key files.其中[KEY_FILENAME]是您用于 SSH 密钥文件的名称。

Repeat this process for every user who needs a new key.为每个需要新密钥的用户重复此过程。

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

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