0

I have a vps running debian that I can access as root over ssh. I would like to set up a user account to allow ssh access. I ssh'd in as root, created a user:

useradd -m user

created a password for the user:

passwd user

and added this user to /etc/ssh/sshd_config file:

AllowUsers user

Then on my local machine, I created a key:

ssh-keygen -t rsa -b 4096 -C "user"

On the vps, I created the file /home/user/.ssh/authorized_keys

and pasted in the public key.

But I am unable to ssh in as user:

$ ssh user@vpshost
user@vpshost: Permission denied (publickey).
$ 

What am I doing wrong? I have read in a few places that I need to restart the ssh service (other places say it is not necessary), but since my only access to the vps is via ssh, and I have read that you cannot restart ssh while on ssh (which makes sense), I wonder if this is the problem.

Suggestions?

2
  • Check the syslogs on the server. Sshd might log the reason why authentication is failing. – Kenster May 23 '20 at 16:14
  • I second checking /var/log/syslog/. Run tail -f /var/log/syslog on the server while trying to SSH from the client to see what's happening in real time. It is, in fact, possible to restart ssh without any connections dropping. Add the contents of /var/log/syslog when trying to connect to your question.. – Nasir Riley May 23 '20 at 18:40
0

typical problem is wrong permissions on files in .ssh folder on server or client. safest way to copy pub key to server is to use ssh-copy-id command, this will set proper permissions on authorized_keys file (either 600 or 640 if i remember right)

you can also try increasing verbosity as

ssh -vvv user@vpshost

1
  • The VPS is running Debian so there is no /var/log/secure. It used /var/log/syslog instead. It's better to wait until he adds the output of /var/log/syslog to his question. – Nasir Riley May 23 '20 at 18:39

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.