Search code examples
google-cloud-shell

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


I have private GIT repo on Bitbucket and would like to push changes I make on Google Cloud Shell back there.

I've enabled Bitbucket -> GCP mirroring, but that seems to be non-bi-directional, i.e.

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

For now, I just added one more remote that points directly to Bitbucket and generated a new SSH key pair to connect:

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 push seems to work fine:

$ git push bitbucket master
Everything up-to-date 

But now the question: will ~/.ssh survive Cloud Shell VM restart? What is the best practice?


Solution

  • .ssh will survive for next session as system wide changes will be changed not the changes in $HOME directory. If you come back before 120 days, you will have the .ssh file. But you might need to install "git" again to use it. For more details I would recommend the following link:
    https://cloud.google.com/shell/docs/limitations
    How does the data in HOME directory persist on cloud shell?