I created a Compute Engine VM (Ubuntu 18.04), and when I log into it using the SSH button in the VM instances list I'm logged in as user
After a while, I realised I needed to be able to use another SSH client as well. As per https://cloud.google.com/compute/docs/instances/connecting-advanced I enabled OS Login by adding a key-value pair in metadata, where key is
enable-oslogin and value is
I then tried to add my existing SSH key:
gcloud compute os-login ssh-keys add --key-file path/to/key.pub --ttl 0
which was successful except one major problem: it has added the key for user
username_gmail_com and will only allow me to ssh to my VM as that user:
And it has also created that user on my VM. From the web interface, I'm logged in to the VM with that new user as well (
/home/username_gmail_com). Of course, I can still access the original user's data (
/home/username). When I disable OS Login the web interface logs me in as
username again and SSH from another client is disabled.
- Why is the username different when enabling OS Login?
- Can I change the username with OS Login enabled?
There has been an addition to the docs explaining exactly this question. Check here: https://cloud.google.com/compute/docs/oslogin/ and on the page I mentioned above all the way at the bottom under "Expected login behaviors".