【发布时间】:2020-03-24 06:24:28
【问题描述】:
生成基于 RSA 的 SSH 密钥后:
ssh-keygen -t rsa -f ~/.ssh/id_rsa -C id_rsa
#=>
Generating public/private rsa key pair.
Created directory '/. . ./.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /. . ./.ssh/.id_rsa.
Your public key has been saved in /. . ./.ssh/.id_rsa.pub.
The key fingerprint is:
SHA256:. . . id_rsa
The key's randomart image is:
+---[RSA 3072]----+
| . . . |
+----[SHA256]-----+
我可以将它添加到我的 Google Cloud Platform (GCP) 项目的 ($GCP_PROJECT_NAME) 计算元数据中:
gcloud compute project-info add-metadata \
--metadata-from-file ssh-keys=./.ssh/id_rsa.pub
#=>
WARNING: The following key(s) are missing the <username> at the front
ssh-rsa . . . id_rsa
Format ssh keys following https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys
Updated [https://www.googleapis.com/compute/v1/projects/$GCP_PROJECT_NAME].
带有警告,但无法使用它连接到 GCP Compute 实例。
如果我:
pbcopy < ~/.ssh/id_rsa.pub
然后我将它粘贴到 GCP Console 中,我就可以使用它了。
我如何使用 GCP SDK (gcloud) 完成同样的事情?
【问题讨论】:
-
显示你的公钥的最后一行。这是用户名部分应该出现的地方,或者只是将公钥添加到您的问题中。
-
我不明白。如何添加用户名?
-
SSH 公钥的格式在 Internet 上有记载。基本上,在最后一行添加`myusername`。但是,这取决于密钥的格式。您甚至可能使用了错误的公钥格式。
-
我不确定您要按照哪个文档在元数据中添加/删除 ssh 密钥。关于“Managing SSH keys in metadata”的帮助中心文章似乎很简单。您是否检查过该文档中的“creating a new SSH key”部分?要添加或删除项目范围的公共 SSH 密钥,您可以参考 this section。
-
感谢您的回复。我的问题是如何通过 gcloud cli 上传 ssh 密钥。我非常仔细地阅读了这两个链接。您能告诉我如何将 ssh 密钥上传到元数据。
标签: google-cloud-platform ssh gcloud ssh-keys gcloud-compute