生成基于 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 计算实例。
如果我:
pbcopy < ~/.ssh/id_rsa.pub
我将它粘贴到 GCP Console 中,我可以使用它。
我如何使用 GCP SDK ( gcloud
) 完成同样的事情?