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

孤者浪人 提交于 2021-01-29 14:24:33

问题


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 from

  • configure 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!