4

Every time I try to enter via SSH into my VM instance in Google Compute Engine I got this error:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

I have attempted the steps mentioned below :

  1. Generated a ssh key using the command ssh-keygen -t rsa -f ~/.ssh/[filename] -C [username]

  2. Copied the public key into instance ssh list.

  3. And then tried to ssh the compute engine using the private key ssh -i [privatekeyname] [username]@[ipaddress]

What could be the issue or am I missing some steps?

Mangu
  • 3,160
  • 2
  • 25
  • 42
Pranay Das
  • 63
  • 1
  • 6

2 Answers2

10

I just had this issue when trying to connect. I changed "enable-oslogin TRUE" to "enable-oslogin FALSE" in the metadata and it started working again.

Jonathan S
  • 546
  • 3
  • 10
  • 1
    Thanks to @Jonathan a lot. I wasted more than 1 hour to solve it. Finally I found the answer of you. The docs said that "you must provide your public SSH key to the instance using one of the following options:...". Then I did both. That's why the error occurred. Hahaa =)) Just following ONE of them. – Daniel Pham Feb 23 '19 at 12:15
  • LIFESAVER. THIS IS IT. THANK YOU. – edrichhans Feb 18 '20 at 10:21
1

Ensure that after creating the key it has been copied correctly into the VM Instance. Sometimes during the copying of the key, either tabs, spaces or other indentation may be added into the key which will result in the key being different from the original one that was created. This is a very common failure reason. It is just not good enough to cat the key file and copy whatever you see. You have to ensure that you have copied the key without tabs, spaces or other indentation that may be added.

Double check that during the connection, with the -i option, you’re using the correct private key.

Use the -v, -vv, or -vvv options with your ssh command to further troubleshoot the issue. These options allow various verbosity levels to be activated during the ssh connection which helps in troubleshooting the issue and see exactly where the problem is.

JMD
  • 610
  • 4
  • 8