UsePAMが「no」に設定されている場合、SSH公開キー認証が失敗する


19

パスワード認証を無効にするには、次の値を設定しました sshd_config

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

秘密鍵でログインしようとすると、

Permission denied (publickey).

その後、に変更UsePAMするyesと、秘密鍵を使用してログインできます。どうして?

OSXからUbuntu 12.04 64ビットホストに接続しています

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

詳細な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).

sshdをデバッグモードで実行し、生成されたログを確認しましたか?
マイケルハンプトン

きっともっとログが必要になるでしょう。(Fedora 17を使用して)VMであなたの状況を再現しましたが、うまくいきました。
スコットパック

回答:


15

PAM(Pluggable Authentication Module)を使用しない場合、認証にはより複雑なssh構成が必要です。実際にこれを探しています:

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

これにより、パスワード付きログインが無効になります。公開鍵設定が正しく確立されていることを確認してください。


4
これは本当ではありません。実際には、多くのガイドは設定をお勧めしますChallengeResponseAuthenticationPasswordAuthenticationUsePAMすべてにnoのみ公開鍵認証を使用します。私はそのような環境で働いたことがないので、まだまだうまくいかない本当の理由を簡単に述べることはできません。
スコットパック

3
私が見つけたすべてのガイドがそれをしたので、そもそも私はそれをいいえに設定した理由です!
エリックアイグナー

訂正します。あなたは正しい、スコット。ただし、pam_unixを使用したくない場合は、pam_nologinを構成する(またはルートアクセスを許可する)必要があります。www-uxsup.csx.cam.ac.uk/ pub / doc / suse / sles9 / adminguide-sles9 /…
ステファン

9

ユーザーアカウントはロックされていますか?ユーザーアカウントのロックを解除できます

passwd -u username

または、ユーザーアカウントをロックしてPAMを有効にします。

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM yes

1
さらに、passwd -uユーザーのパスワードが空の場合は失敗します。echo username:$(head -c12 /dev/urandom |base64) |chpasswdランダムな有効なパスワードを設定するために使用します。
手元

usermod -p '*' username3つすべてを「no」に設定し、「username」が公開パスワード認証を使用して、使い捨てのパスワードを設定せずに接続できるようにします。
デビッド
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.