问题
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?
回答1:
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
回答2:
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 fromconfigure your home directory on a persistent disk which would survive across instance reloads
来源:https://stackoverflow.com/questions/53446990/how-do-i-add-a-ssh-key-to-google-cloud-compute-engine-vm-linux-instance