デフォルト以外のキーファイルを使用すると、SSH がパスワードを要求し続けます

デフォルト以外のキーファイルを使用すると、SSH がパスワードを要求し続けます

という名前のキーファイルがありKEYKEYと がありますKEY.pub。 pub を にアップロードしauthorized_keys、 private を で追加します。

ssh-add /home/user/.ssh/KEY

しかし、 に接続しようとすると、パスワードの入力を求められます。ssh [email protected]

デフォルトのキー名のままキーを生成しssh-keygen、pubをアップロードしてprivateをロードすると、ではないパスワードをリクエストします。

何が問題なのでしょうか?

答え1

デバッグ出力を取得でき、おそらく (ssh のデフォルトのキー ファイル) で認証できないことが通知されます。答えは、どのキーを使用するかを ssh に指示することです。ssh -vvv [email protected]~/.ssh/id_rsa

ssh -i /home/user/.ssh/KEY [email protected]

ホストごとのキーファイルを に追加することもできます.ssh/config。その場合は、入力するだけssh host.comで、ユーザー/キーが自動的に選択されます。

.ssh/config のエントリ例(詳細については、以下を参照してくださいman ssh_config):

Host mysshserver ssh.host.com
HostName ssh.host.com
User myusername
IdentityFile ~/.ssh/mykeyfile


キーファイルの説明man ssh:

 -i identity_file
             Selects a file from which the identity (private key) for RSA or
             DSA authentication is read.  The default is ~/.ssh/identity for
             protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro‐
             tocol version 2.  Identity files may also be specified on a per-
             host basis in the configuration file.  It is possible to have
             multiple -i options (and multiple identities specified in config‐
             uration files).

答え2

キーファイルを正しく設定するには(ハウツーここ)、次の点に注意してください。

.sshホストディレクトリとファイルに適切な権限がない場合、および/またはリモート ユーザーのホーム ディレクトリに適切な権限がない場合、ssh はキー ファイルを見つけてもパスワードを要求し続けます。

キーファイルが提供されているかどうかを確認するには、ssh -vvv user@host

出力例:

debug1: Offering DSA public key: /Users/<user>/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

リモートユーザーのホームディレクトリとリモート.sshディレクトリの権限の両方を確認します

たとえば、権限は次のようになります。

$ls -ld .ssh
drwx------ 2 <owner> <group> 4096 2011-12-29 20:39 .ssh

$ls -ld ~/
drwxr-xr-x 28 <owner> <group> 4096 2011-12-29 20:15 /home/<user>/ 

関連情報