1

This question already has an answer here:

I have a ubuntu 16.04 server install that was initially installed with root user only so root users home directory is /root. If I add another user such as bob bobs home directory is created in /home/ as expected. If I want add a public key for bob to ssh in with, I add /home/bob/.ssh/authorized_keys and put bobs public key in the authorized key file. Is this the correct way so far? Problem is when I try

ssh bob@server.com 

I get

Permission denied (publickey)

The .ssh directory permissions are set to 700 and the authorized_key file is set to 600. In my sshd_config the path to the key file is the default

#AuthorizedKeysFile     %h/.ssh/authorized_keys

I set ssh logging to verbose but it only shows

Failed publickey for....

What could I be doing wrong? Is it only looking in /root/.ssh for the key file?

marked as duplicate by Gilles ssh Sep 4 '17 at 20:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    ssh -vvv bob@server.com and see why it is failing. – jasonwryan Sep 3 '17 at 1:32
  • 1
    Have a look at the system log on the server. – Hauke Laging Sep 3 '17 at 1:44
  • Make sure the public key you entered into authorized_keys is free of spaces (in the actual keystring), line breaks, etc. – Patrick Sep 3 '17 at 1:50
  • is sshd server running on the remote server? – aurelien Sep 3 '17 at 7:13
  • @aurelien How does a non-running server give you "Permission denied"? – Hauke Laging Sep 3 '17 at 9:21
0

If you are using ssh bob@server.com then based on your sshd_config file, the server is looking in the correct location (i.e. /home/bob/.ssh/authorized_keys).

However, based on your description I cannot tell if the key that you pasted in to the authorized_keys file is in fact the same one that the client is trying to ssh with. Rather than manually pasting it into the authorized_keys file, using ssh-copy-id bob@server.com from the client machine will ensure that the public key in use by the ssh client is correctly added to your server's authorized_keys file (for user bob).

0

Verifying that you're using the correct key is the first step. Also check the sshd config to make sure public key authentication is enabled:

RSAAuthentication yes
PubkeyAuthentication yes

Then also check to see if there are any "allow/deny" settings like "AllowGroups", "DenyGroups", "AllowUsers", and "DenyUsers" which will prevent anyone not in that group or user from logging in. Another setting is "AuthenticationMethods" which may prevent the public key authentication alone from working.

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