I am trying to set up a new user on my remote server.

I have created a new user with sudo access.

adduser username
usermod -aG sudo username

Then in the /etc/ssh/sshd_config file I have allowed that user ssh access.

AllowUsers username root

and I restarted ssh.

service sshd reload

Finally I logged in as the user and copied my public ssh key into the ~/.ssh/authorized_keys file.

But I still get Permission denied (publickey) when I try to ssh as that user.

ssh username@mydomain.com

I am able to ssh as the root user with no problems.

ssh root@mydomain.com

Am I missing something?

  • 2
    Probably permissions problems. What are the permissions of the home directory of that user, what are the permissions of ~/.ssh directory and the ~/.ssh/authorized_keys file in the users home directory? Where is the private key of that user used to authentication? – Jakuje May 18 '17 at 18:29
  • The ~/.ssh directory has drwxrwxr-x. The ~/.ssh/authorized_keys has -rw-rw-r--. The remote user has an ssh key in the ~/.ssh directory and so does my local user. – Chris Starling May 18 '17 at 18:45
  • Run ssh with the -vvv flags. – Faheem Mitha May 18 '17 at 18:53
  • I'm not sure what to make of it. This is the end of the log that appears when I run ssh -vvv debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 51 – Chris Starling May 18 '17 at 19:13

From the SSH tag wiki:


If public key authentication doesn't work: make sure that on the server side, your home directory (~), the ~/.ssh directory, and the ~/.ssh/authorized_keys file, are all writable only by their owner. In particular, none of them must be writable by the group (even if the user is alone in the group). chmod 755 or chmod 700 is ok, chmod 770 is not.

What to check when something is wrong:

  • Run ssh -vvv to see a lot of debugging output. If you post a question asking why you can't connect with ssh, include this output (you may want to anonymize host and user names).
  • If you can, check the server logs, typically in /var/log/daemon.log or /var/log/auth.log or similar.
  • If public key authentication isn't working, check the permissions again, especially the group bit (see above).

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.