0

From google compute engine instance, connected via ssh with web terminal

[gcp-instance] $ ssh-copy-id user@server           
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
user@server's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'user@server'" and check to make sure that only the key(s) you wanted were added.
[gcp-instance] $ ssh user@server
Welcome to Linux Mint 18.3 Sylvia (GNU/Linux 4.4.0-142-generic x86_64)
....
[user@server] $

Sweet, it worked.

On server, set :/etc/ssh/sshd_config PasswordAuthentication no

Log out of server and try it again...

[user@server] $ exit
[gcp-instance] $ ssh user@server
Welcome to Linux Mint 18.3 Sylvia (GNU/Linux 4.4.0-142-generic x86_64)
....
[user@server] $

Sweet, it worked again, now log out of server and GCE instance...

[user@server] $ exit
[gcp-instance] $ exit

Log into GCE instance again in the web interface...

[gcp-instance] $ ssh user@server
Permission denied (publickey).

Why did it work the first time and second, but it did not work on the third try, after restarting GCE instance?

  • 1
    Have you set up OS login? cloud.google.com/compute/docs/instances/… – Bungicasse Feb 23 at 17:48
  • 1
    By default, Compute Engine adds the generated key to project or instance metadata. Every instance stores its metadata on a metadata server, so it is only saved to that specific instance – Bungicasse Feb 23 at 17:49
  • @Bungicasse No, I haven't. I will look into that. I prefer to tunnel ssh over http, and I was assuming OS login meant that you login from a shell instead of through a browser. – jsp Feb 23 at 21:21
  • @Bungicasse Thanks for the metadata explanation, that makes sense. Keys are ephemeral. – jsp Feb 23 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.