来自 Google 云 Shell 的出站连接的 SSH 凭据最佳实践

Best practice for SSH credentials for outbound connections from Google Cloud Shell

我在 Bitbucket 上有私人 GIT 存储库,我想将我在 Google Cloud Shell 上所做的更改推送回那里。

我启用了 Bitbucket -> GCP 镜像,但这似乎是非双向的,即

git push origin master
fatal: remote error: The remote repository is a read-only mirror of https://bitbucket.org/<repo_name>

现在,我只是添加了一个直接指向 Bitbucket 的远程设备并生成了一个新的 SSH 密钥对来连接:

git remote add bitbucket git@bitbucket.org:<user>/<repo_name>.git
ssh-keygen -t rsa -b 4096 -C "name@domain.com"
ssh-add ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub

Git 推送似乎工作正常:

$ git push bitbucket master
Everything up-to-date 

但现在的问题是:~/.ssh 能否在 Cloud Shell VM 重启后继续存在?最佳做法是什么?

.ssh 将在下一个会话中继续存在,因为系统范围的更改将被更改,而不是 $HOME 目录中的更改。如果您在 120 天之前回来,您将拥有 .ssh 文件。但是您可能需要再次安装 "git" 才能使用它。有关更多详细信息,我会推荐以下 link:
https://cloud.google.com/shell/docs/limitations
How does the data in HOME directory persist on cloud shell?