On server i have only ssh auth, but for one user I need to add a specific folder and password based auth. So I created a user

sudo adduser myuser

then in /etc/ssh/sshd_config file I added:

Match User myuser
    PasswordAuthentication yes
    RSAAuthentication no
    PubkeyAuthentication no
Match all
    PasswordAuthentication no

Then restart service service sshd restart

But I still get an error:

Permission denied (publickey,password).

System: FreeBSD 10.1-RELEASE (GENERIC)

First, the user will need to be added to AllowUsers at the bottom of the file. I'm sure that you've already created myuser and set up a password on the machine you're trying to ssh into.

AllowUsers myuser

If it's not there then you'll need to add it at the very end of the file.

Get rid of the "match myuser" and "match all" part and set Password Authentication to yes and Pubkey authentication to no for the time being and then restart the sshd service on the computer you're trying to connect to.

You'll need to first create and then copy the public key over to the folder using the ssh-copy-id command on the computer you're connecting from. Log into the computer from which you are trying to connect as "myuser" and then run the following command:

ssh-keygen -t rsa

It will ask you to enter and confirm a pass phrase for the key and then it will tell you where it has been saved, show the fingerprint, and then the random art image.

The following will copy the public key over to the computer you're trying to connect to. It will prompt you for myuser's password.

ssh-copy-id -i ~/.ssh/id_rsa.pub myuser@host

If you're using a port other than 22, use the following:

ssh-copy-id -p #portnumber -i ~/.ssh/id_rsa.pub myuser@host

After you've done that, you can set Password Authentication to no and Pubkey Authentication to yes on the computer you're trying to connect to and restart the ssh service once again. Try to connect as myuser and it should prompt you for the pass phrase that you created and connect using pubkey authentication.

  • I don't see option AllowUsers in sshd file. And when I did all that you said still nothing work – Arti Jan 18 at 12:48
  • I've edited my answer to address a few things. Make sure that you are restarting the sshd service after each change. – Nasir Riley Jan 18 at 13:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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