簡體   English   中英

如何將 SSH 密鑰添加到 Google Cloud Compute Engine VM Linux 實例?

[英]How do I add a SSH key to Google Cloud Compute Engine VM Linux instance?

我有一個在 Google Cloud Platform 中運行的 Linux VM 實例。 我試圖將我的公鑰復制到~/.ssh/authorized_keys並且我可以成功地通過 SSH 連接到我的 VM。

但有時~/.ssh/authorized_keys被刷新,我必須再次復制公鑰。 每次添加公鑰真的很痛苦。 如何永久添加公鑰?

〜/ .ssh / authorized_keys從元數據中獲取ssh密鑰。 它最好你把你的SSH公共密鑰在元數據中提到這里也有一個堆棧討論這里

文件“消失”的一個可能原因是,每次重新加載實例時,都會從不包含該文件的同一VM映像中重新加載該實例。 檢查這些事件是否與實例重新加載相關聯,以及主目錄中的其他文件是否也消失了,如果這樣做,則可能是罪魁禍首。 如果是這樣,我可以看到幾種可能的方法:

  • ~/.ssh/authorized_keys文件(當然還有用戶和主目錄配置)包含到自定義VM映像中 ,然后可以使用該映像從中啟動實例

  • 永久磁盤上配置您的主目錄,該目錄將在實例重新加載后繼續存在

您可以通過向 VM 添加 SSH 密鑰來跟蹤元數據管理的 SSH 連接

要使用 Cloud Console 將公共 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>"}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM