To disable password auth I've set the following values in my sshd_config

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

When I try to log in with my private key I get

Permission denied (publickey).

If I then change UsePAM to yes I can login using my private key. Why?

I'm connecting to a Ubuntu 12.04 64bit host from OSX

ssh -i ~/.ssh/deploy -l deploy localhost -p 2222 -v

here's the verbose ssh output:

OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/<user>/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to localhost [] port 2222.
debug1: Connection established.
debug1: identity file /Users/<user>/.ssh/deploy type 1
debug1: identity file /Users/<user>/.ssh/deploy-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 50:db:75:ba:11:2f:43:c9:ab:14:40:6d:7f:a1:ee:e3
debug1: Host '[localhost]:2222' is known and matches the RSA host key.
debug1: Found key in /Users/<user>/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/<user>/.ssh/key1
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /Users/<user>/.ssh/deploy
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
  • Did you run sshd in debug mode and check the log it generates? Feb 6, 2013 at 2:18
  • We're definitely going to need more logs. I replicated your situation in a VM (using Fedora 17) and it worked for me.
    – Scott Pack
    Feb 6, 2013 at 2:40

2 Answers 2


Without PAM (Pluggable Authentication Module) more complicated ssh configuration is required to authenticate. You're looking for this, actually:

# grep Password /etc/ssh/sshd_config 
PermitEmptyPasswords no
PasswordAuthentication no

This will disable passworded login. Ensure you public key settings correctly established.

  • 6
    This isn't really true. In fact, many guides recommend setting ChallengeResponseAuthentication, PasswordAuthentication, and UsePAM all to no and using only public key authentication. I've never worked in such an environment, so I can't easily give a real reason why it's not working quite yet.
    – Scott Pack
    Feb 6, 2013 at 2:27
  • 3
    Thats why I set it to no in the first place, because every guide I found did it!
    – user22711
    Feb 6, 2013 at 2:30
  • I'll stand corrected; you're correct, Scott. That said, if he doesn't wish to use pam_unix, he'll need to configure pam_nologin (or allow root access.) www-uxsup.csx.cam.ac.uk/pub/doc/suse/sles9/adminguide-sles9/…
    – Stephan
    Feb 6, 2013 at 2:36
  • Just go for the most no and the least possible yes. sudo nano /etc/ssh/sshd_config.d/50-redhat.conf; sudo systemctl restart sshd.service ChallengeResponseAuthentication no PasswordAuthentication no PermitEmptyPasswords no PubkeyAuthentication yes UsePAM no ...enables you to login with your private key only and even though the user has a password, the password login is always denied.
    – Alex
    Jul 5, 2021 at 0:25

Is your user account locked? You can either unlock the user account

passwd -u username

or lock the user account but enable PAM:

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM yes
  • 1
    Plus, passwd -u fail if user has empty password. Use echo username:$(head -c12 /dev/urandom |base64) |chpasswd to set random valid password.
    – temoto
    Mar 24, 2016 at 12:30
  • 1
    usermod -p '*' username will let you have all three set to "no", and a still allow "username" to connect using public key authentication without having to set a throwaway password.
    – David
    Feb 26, 2017 at 5:06

You must log in to answer this question.