1
votes

I have a Linux VM instance running in Google Cloud Platform. I tried to copy my public key to ~/.ssh/authorized_keys and I can successfully SSH to my VM.

But sometimes ~/.ssh/authorized_keys is flushed and I have to copy the public key again. It is really a pain to add public key every time. How do I add a public key permanently?

2
Are other files in your home dir disappearing as well (is the homedir wiped)? - Dan Cornilescu
No, they are just the same. - Valeri

2 Answers

0
votes

This ~/.ssh/authorized_keys takes the ssh keys from the metadata. It best you keep your ssh public keys in the metadata as mentioned here and there’s also a stack discussion here

0
votes

One possible reason for which the file would "disappear" would be that every time the instance is reloaded it is reloaded from the same VM image, which doesn't contain the file. Check if the occurences are correlated with the instance reloading and if other files in your home dir disappear as well, if they do that's likely the culprit. If so I can see a couple of possible approaches:

  • include the ~/.ssh/authorized_keys file (and, of course, your user and home directory configurations) into a custom VM image that you could then use to boot your instances from

  • configure your home directory on a persistent disk which would survive across instance reloads