web-dev-qa-db-fra.com

L'authentification de la clé publique SSH échoue lorsque UsePAM est défini sur "non"

Pour désactiver l'authentification par mot de passe, j'ai défini les valeurs suivantes dans mon sshd_config

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

Lorsque j'essaie de me connecter avec ma clé privée, je reçois

Permission denied (publickey).

Si je change ensuite UsePAM en yes je peux me connecter en utilisant ma clé privée. Pourquoi?

Je me connecte à un hôte Ubuntu 12.04 64 bits d'OSX

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

voici la sortie verbeuse ssh:

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 [127.0.0.1] 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_REQUEST sent
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).
21
Erik Aigner

Sans PAM (Pluggable Authentication Module), une configuration ssh plus compliquée est requise pour l'authentification. Vous cherchez cela, en fait:

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

Cela désactivera la connexion par mot de passe. Assurez-vous que les paramètres de clé publique sont correctement définis.

16
Stephan

Votre compte utilisateur est-il verrouillé? Vous pouvez soit déverrouiller le compte utilisateur

passwd -u username

ou verrouillez le compte utilisateur mais activez PAM:

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM yes
10
hanxue