我有一个运行在Google Cloud平台上的Linux VM实例。我尝试将我的公钥复制到~/.ssh/authorized_keys,然后我可以成功地通过SSH连接到我的VM。
但有时~/.ssh/authorized_keys会被刷新,我必须再次复制公钥。每次添加公钥都是一件痛苦的事情。如何永久添加公钥?
发布于 2018-11-24 02:54:10
发布于 2018-11-25 03:26:32
文件“消失”的一个可能原因是,每次重新加载实例时,都会从不包含该文件的相同VM映像中重新加载该实例。检查出现的情况是否与实例重新加载相关,如果您的主目录中的其他文件也消失了,如果他们消失了,这很可能是罪魁祸首。如果是这样的话,我可以看到几种可能的方法:
~/.ssh/authorized_keys文件(当然还有您的用户和主目录配置)包含到一个custom VM image中,然后您可以使用该文件从启动您的实例
期间继续存在
发布于 2021-12-30 11:33:39
你可以通过adding SSH keys to VMs关注Metadata-managed SSH connections
要使用云控制台将公有SSH密钥添加到项目元数据中,请执行以下操作:
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>"}格式
https://stackoverflow.com/questions/53446990
复制相似问题