1

I recently moved away from my windows machine and am now on ubuntu 18.04, however, whenever I try logging in to my remote servers using ssh <username>@<serverIp>, I get a Permission denied (public key) error. In my opinion, If I am using the same public and private keys, it should have worked, not sure what am I doing wrong here.

7
  • Did you add the contents of ~/.ssh/id_rsa.pub from the client to the ~/.ssh/authorized_keys file on the server? – Terrance Feb 26 '19 at 5:22
  • Shouldn't it already be there since I was logging in using the same key, just a difference pc. – Adit A. Pillai Feb 26 '19 at 5:35
  • You need to make sure that the id_rsa.pub or whatever pub key you are using on the client matches exactly in the authorized_keys in the server. All the way to the PC name itself. Also, make sure that the permissions on the key files are correct at rw------- or chmod 600 filename. Open permissions can cause failures in connecting as well. – Terrance Feb 26 '19 at 5:42
  • additionally run ssh -vv user@host and edit your post to include this. This contains debug info about which keys were tried, and possibly why they were refused. – vidarlo Feb 26 '19 at 6:00
  • sure, let me upload the results here. – Adit A. Pillai Feb 26 '19 at 8:12
2

The permissions on the key files are too open. They need to be set to owner only. ssh requires that the permissions be set to the owner only for security reasons. Too open of permissions like 664, 644, etc can cause ssh to fail with the error of permissions.

The following will set the permissions to Read / Write or rw------- for the owner only:

chmod 600 id_rsa
chmod 600 id_rsa.pub
chmod 600 authorized_keys

You can even set the id_rsa and the id_rsa.pub to Read Only with a permission of 400 or r--------. I recommend leaving the authorized_keys and known_hosts at 600 just in case you need to add another key to it from another computer.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.