web-dev-qa-db-ja.com

公開鍵ssh認証の使用方法

2つのubuntu12.04(ベータ)サーバー(node1とnode2)があり、それらの間にパスワードなしのルートアクセスを確立したいと考えています。他のユーザーは他のボックスにアクセスできないようにする必要があります。また、sshのデフォルトポートが220に変更されていることにも注意してください。

これが私がしたことです:

Sudo -i
cd /root/.ssh
ssh-keygen -t rsa # with default name and empty password
cat id_rsa.pub > authorized_keys

次に、id_rsaとid_rsa.pubをnode2にコピーし、id_rsa.pubをauthorized_keysに追加しました。両方のホストに同じ/root/.ssh/configファイルがあります。

Host node1
Hostname 1.2.3.4
Port 220
IdentityFile /root/.ssh/id_rsa

Host node2
Hostname 5.6.7.8
Port 220
IdentityFile /root/.ssh/id_rsa

ここで問題となるのは、ssh node2と入力すると、パスワードの入力を求められることです。何が問題なのですか?

更新:

クライアントのデバッグ情報:

debug1: Server Host key: RSA ***
debug1: Host '[*.*.*.*]:220' is known and matches the RSA Host key.
debug1: Found key in /root/.ssh/known_hosts:6
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/id_rsa ((nil))
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: read PEM private key done: type RSA
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
debug1: Next authentication method: password

サーバーのデバッグ情報:

debug1: userauth-request for user root service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: PAM: initializing for "root"
debug1: PAM: setting PAM_RHOST to "*.*.*.*"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: userauth-request for user root service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: test whether pkalg/pkblob are acceptable [preauth]
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: matching key found: file /root/.ssh/authorized_keys, line 2
Found matching RSA key: ****
debug1: restore_uid: 0/0
debug3: mm_answer_keyallowed: key 0x7f0647b0c1b0 is allowed
debug3: mm_request_send entering: type 22
debug2: userauth_pubkey: authenticated 0 pkalg ssh-rsa [preauth]
Postponed publickey for root from *.*.*.* port 38887 ssh2 [preauth]

権限:

drwx------ 2 root root   4096 Mar 26 15:34 .ssh

-rw------- 1 root root  840 Mar 26 14:50 authorized_keys
-rw-r--r-- 1 root root  225 Mar 26 15:34 config
-rw------- 1 root root 1679 Mar 26 14:47 id_rsa
-rw-r--r-- 1 root root 2652 Mar 26 14:39 known_hosts

設定ファイルからのいくつかの行:

PermitRootLogin without-password
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  %h/.ssh/authorized_keys
UsePAM no # also tried yes
5
Poma

Rootのホームディレクトリは暗号化されていますか(おそらくecryptfsによって)?

ユーザーがすでにアクティブなセッションを持っていない限り、公開鍵認証が機能しないという同様の問題がありました。読み取り この質問 、ユーザーのホームディレクトリを暗号化することを選択することで、ユーザーが別のセッションに既にログインしていない限り、sshdが〜/ .ssh/authorized_keysを読み取れないようにしていることに気付きました(自動的に復号化されます)ホームディレクトリ)。

暗号化されていないホームディレクトリに切り替えることで問題を解決しました。その後、公開鍵認証が機能し始めました。

3
eallrich

sshには、公開鍵をリモートサーバーssh-copy-idにコピーするコマンドが付属しています。必要な権限やその他のさまざまな「落とし穴」の問題を処理します。

例:

ssh-copy-id -i $HOME/.ssh/id_dsa [email protected]

ssh-copy-idでコピーした後、sshのときにパスワードの入力を求められることはなくなりました。

1
Michael Hampton

いくつかの提案:

  • /root/.ssh(およびその内容)の権限を確認してください
  • Sshがrootログインおよび/または公開鍵認証を許可するかどうかを確認します(/ etc/ssh/sshd_config iirc)
  • ssh -v -vを使用して、より多くのデバッグ出力を確認します
0
jakob

デバッグするには、LogLevel DEBUG/etc/ssh/sshd_configを使用します。考えられる落とし穴の1つは、.sshの下にあるはずの/home/someuser/ディレクトリを/root/に置くことです。

0
tuomassalo

システムに暗号化されたユーザーが1人いたため、これに遭遇しました。これにより、sshdは、すべてのユーザーディレクトリが暗号化され、authorized_keysファイルが/etc/ssh/username/authorized_keysの下にあるという前提になります。

私にとっては、認証されたキーを/etc/ssh/username/に移動し、次にchown -R username:username /etc/ssh/username/に移動した後、機能しました。面白いことに、暗号化されていないユーザーも含め、すべてのユーザーに対してこれを実行する必要がありました。

0
ansi_lumen