首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向Google Cloud Compute Engine VM Linux实例添加SSH密钥?

问如何向Google Cloud Compute Engine VM Linux实例添加SSH密钥?
EN

Stack Overflow用户
提问于 2018-11-23 20:46:10
回答 3查看 5.1K关注 0票数 1

我有一个运行在Google Cloud平台上的Linux VM实例。我尝试将我的公钥复制到~/.ssh/authorized_keys,然后我可以成功地通过SSH连接到我的VM。

但有时~/.ssh/authorized_keys会被刷新,我必须再次复制公钥。每次添加公钥都是一件痛苦的事情。如何永久添加公钥?

EN

回答 3

Stack Overflow用户

发布于 2018-11-24 02:54:10

这个~/.ssh/authorized从元数据中获取ssh密钥。您最好将ssh公钥保存在元数据中,就像前面提到的here一样,还有一个堆栈讨论here

票数 0
EN

Stack Overflow用户

发布于 2018-11-25 03:26:32

文件“消失”的一个可能原因是,每次重新加载实例时,都会从不包含该文件的相同VM映像中重新加载该实例。检查出现的情况是否与实例重新加载相关,如果您的主目录中的其他文件也消失了,如果他们消失了,这很可能是罪魁祸首。如果是这样的话,我可以看到几种可能的方法:

  • 将~/.ssh/authorized_keys文件(当然还有您的用户和主目录配置)包含到一个custom VM image中,然后您可以使用该文件从

启动您的实例

期间继续存在

票数 0
EN

Stack Overflow用户

发布于 2021-12-30 11:33:39

你可以通过adding SSH keys to VMs关注Metadata-managed SSH connections

要使用云控制台将公有SSH密钥添加到项目元数据中,请执行以下操作:

代码语言:javascript
复制
1. In the Cloud Console, go to the Metadata page.

2. Go to Metadata > Under SSH Keys, click Edit.

3. Click Add item. A text box opens.

4. Add your public key in the text box. The key must be in one of the following formats:

Format for a key without an expiration time:

KEY_VALUE USERNAME
Format for a key with an expiration time:

KEY_VALUE google-ssh {"userName":"USERNAME","expireOn":"EXPIRE_TIME"}
Replace the following:

KEY_VALUE: the public SSH key value
USERNAME: the username for the SSH key, specified when the key was created
EXPIRE_TIME: the time the key expires, in ISO 8601 format. For example: 2021-12-04T20:12:00+0000
5. Click Save.

注意Required format: <protocol> <key-blob> <username@example.com> or <protocol> <key-blob> google-ssh {"userName":"<username@example.com>","expireOn":"<date>"}格式

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53446990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档