无法通过云壳终端ssh【谷歌云平台】

时间:2021-03-05 19:05:49

标签: google-cloud-platform ssh virtual-machine

这几天我一直在尝试通过 SSH 云 shell 登录和使用我的虚拟机,我一直没有问题。

这里是我得到的错误

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.

挖掘了一下之后,我在我的连接日志中发现了这个更详细的错误:

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

我试图增加我的虚拟机磁盘空间,但结果是一样的。

此时我认为最简单的方法是在那里下载我的脚本,但如何访问文件?

1 个答案:

答案 0 :(得分:0)

如果您想首先更改或增加磁盘大小,您必须创建一个新实例并从快照重新创建启动磁盘以调整其大小。您可以通过此链接执行此操作 Recovering an inaccessible instance or a full boot disk

  1. 转到VM instances创建页面

Google Cloud -> Compute Engine ->VM 实例

一个。点击实例名称以打开虚拟机实例详情页面。

B.点击停止

c.在启动盘部分,记下启动盘的大小和名称。

  1. 在 Google Cloud Console 中,转到Snapshots创建页面。

Google Cloud -> Compute Engine -> 存储 -> 快照

一个。输入快照名称

B.从源磁盘下拉列表中选择启动磁盘。

c.点击创建

  1. 转到虚拟机实例创建页面。

Google Cloud -> Compute Engine ->VM 实例

  1. 输入实例详细信息。

  2. 从旧启动盘的快照创建一个新的启动盘。

一个。在启动盘下,选择更改

B.选择快照

c.从快照下拉列表中选择旧启动盘的快照。

d。选择启动磁盘类型

e.输入磁盘的新大小。

f.点击选择以确认您的磁盘选项。

  1. 点击创建

  2. 安装并格式化磁盘。

另一个选项是将磁盘附加到虚拟机:Formatting and mounting a zonal persistent disk

另外,我建议您对磁盘进行快照或克隆,以避免丢失数据的风险。

要执行此操作,请转到 disks

Google Cloud -> Compute Engine ->磁盘

选择您的磁盘,然后在操作工具栏中选择创建快照克隆磁盘选项来执行此操作。

如果您只需要调整磁盘大小,您可以在这部分进行:Resizing a zonal persistent disk

转到您的磁盘页面

Google Cloud -> Compute Engine ->磁盘

  1. 点击您的磁盘名称

  2. 点击编辑按钮

  3. 属性中,您可以更改磁盘的大小

  4. 点击保存按钮

然后你需要重新启动你的虚拟机,你的更改将被应用

编辑 03082021

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

编辑 03092021

要添加或删除 SSH 密钥,您需要按照以下步骤操作: Adding or removing project-wide public SSH keys

要从 Cloud Console 添加或删除项目范围的公共 SSH 密钥:

  1. 在 Google Cloud Console 中,转到您项目的元数据页面。 Go to the Metadata page

  2. SSH 密钥下,点击编辑

  3. 修改项目范围的公共 SSH 密钥:

要添加公共 SSH 密钥,请点击添加项目。一个文本框打开。

public SSH key file 的内容复制并粘贴到文本框中。

为要添加的每个公共 SSH 密钥重复此过程。

要删除公共 SSH 密钥,请单击其旁边的删除按钮: alt text

对要删除的每个公共 SSH 密钥重复此过程。

  1. 完成 SSH 密钥编辑后,点击保存

在这里创建一个新的 SSH 密钥 Creating a new SSH key

在你的工作站上打开一个终端

运行这个命令:

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

替换以下内容:

[KEY_FILENAME] :您要用于 SSH 密钥文件的名称。例如,文件名 my-ssh-key 会生成一个名为 my-ssh-key 的私钥文件和一个名为 my-ssh

的公钥文件

[USERNAME]:连接到 VM 的用户的名称。例如,youremail@gmail.com

这是一个例子:

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

接下来是选择一个你记得的密码并确认密码

  1. 限制对您的私钥的访问,以便只有您可以读取它而没有人可以写入它

    chmod 400 ~/.ssh/[KEY_FILENAME]

其中 [KEY_FILENAME] 是您用于 SSH 密钥文件的名称。

对需要新密钥的每个用户重复此过程。