web-dev-qa-db-ja.com

SSHが突然パスワードを要求する

注:これは このStackOverflowの質問 の複製です。ALi786がここの方が良いと示唆しているためです。

一般的な問題

コンピューター(Mac OSX 10.9.4)とリモートサーバー(Ubuntu 14.04.1 LTS)があり、rootとしてSSH接続しています。 ssh-keygenを使用して(パスフレーズなしで)sshキーを作成し、サーバーの.ssh/authorized_keysに公開キーを追加しましたが、すべてが順調でした。それから、今日の初めに、sshは私に再びパスワードを要求し始めました。

何が原因だったのか

何がこれを引き起こしたのか本当にわかりません-これらは私の最良の推測です:

  • 誤ってgitリポジトリをそこにコピーしたときに、リモートサーバーのホームディレクトリからいくつかのファイルを削除する必要がありました(コミットも何もしませんでした。コピーしてからrm'dしました) 。コマンド履歴からわかることから、削除したssh関連のファイルはなく、.git、.gitignore、およびさまざまな* .swだけですか? vimから残ったファイル。
  • リモートサーバーでssh-keygen -l -f ~/.ssh/authorized_keysを実行して、そのファイル内の(私が思うに)キーのフィンガープリントを確認しました。

関連ログ

ssh -v -i ~/.ssh/mykey_rsa root@serveripを実行すると、次のようになります。

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/myusername/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 50: Applying options for *
debug1: Connecting to {ip address} [{ip address}] port 22.
debug1: Connection established.
debug1: identity file .ssh/mykey_rsa type 1
debug1: identity file .ssh/mykey_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH*
debug1:  Miscellaneous failure (see text)
No credentials cache file found

debug1:  An invalid name was supplied
unknown mech-code 0 for mech 1 2 752 43 14 2

debug1:  Miscellaneous failure (see text)
unknown mech-code 0 for mech 1 3 6 1 5 5 14

debug1:  Miscellaneous failure (see text)
unknown mech-code 2 for mech 1 3 6 1 4 1 311 2 2 10

debug1:  An unsupported mechanism was requested
unknown mech-code 0 for mech 1 3 5 1 5 2 7

debug1:  Miscellaneous failure (see text)
unknown mech-code 0 for mech 1 3 6 1 5 2 5

debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] 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 {fingerprint}
debug1: Host '{ip address}' is known and matches the RSA Host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:16
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,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: .ssh/otherkey_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: .ssh/mykey_rsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
root@serverip's password: 

使用するように指示したキー(mykey_rsa)の前に別のsshキー(otherkey_rsa)を試したのはちょっと奇妙だと思いますが、これをうまく解析するためのsshについては十分にわかりません。

一方、リモートサーバーの/var/log/auth.logは参考に

Aug 12 02:04:19 servername sshd[22147]: error: Could not load Host key: /etc/ssh/ssh_Host_ed25519_key
Aug 12 02:04:19 servername sshd[22147]: Authentication refused: bad ownership or modes for directory /root

権限

ローカル/私のコンピューター上:

~/                     drwxr-xr-x+ 105 myusername staff 3570 Aug 11 23:14
~/.ssh/                drwx------   13 myusername staff  442 Aug 11 23:14
~/.ssh/mykey_rsa.pub   -rw-r--r--    1 myusername staff  397 Aug  5 20:52
~/.ssh/mykey_rsa       -rw-------    1 myusername staff 1675 Aug  5 20:52

リモート/サーバー上:

~/                     drwxr-xr-x    8        501 staff 4096 Aug 12 02:16
~/.ssh/                drwx------    2       root root  4096 Aug 12 01:49
~/.ssh/authorized_keys -rw-------    1       root root   794 Aug 12 01:44

リモートで/etc/ssh/ディレクトリ:

/etc/ssh $ ls -la
drwxr-xr-x  2 root root   4096 Aug 12 11:01 .
drwxr-xr-x 96 root root   4096 Aug 12 01:40 ..
-rw-r--r--  1 root root 242091 Apr 14 08:13 moduli
-rw-r--r--  1 root root   1690 Apr 14 08:13 ssh_config
-rw-r--r--  1 root root   2528 Apr 17 15:43 sshd_config
-rw-------  1 root root    672 Aug  6 00:41 ssh_Host_dsa_key
-rw-r--r--  1 root root    606 Aug  6 00:41 ssh_Host_dsa_key.pub
-rw-------  1 root root    227 Aug  6 00:41 ssh_Host_ecdsa_key
-rw-r--r--  1 root root    178 Aug  6 00:41 ssh_Host_ecdsa_key.pub
-rw-------  1 root root   1679 Aug  6 00:41 ssh_Host_rsa_key
-rw-r--r--  1 root root    398 Aug  6 00:41 ssh_Host_rsa_key.pub
-rw-r--r--  1 root root    338 Apr 17 11:48 ssh_import_id

したがって、/etc/ssh/ssh_Host_ed25519_keyを読み込めなかった理由は、存在しないためと思われます。それをすべきですか?もしそうなら、どうすればそれを作成できますか?

私はこれに本当に困惑していて、本当に助けていただければ幸いです!ありがとうございました!

5
Tasha

auth.logは、問題が何であるかを正確に示しています。/rootは、remoteuserまたはroot以外のユーザーによって所有されていますが、ログインにはどういうわけか不可欠です。 remoteuser is root、またはその.sshファイルは/rootの下のどこかにシンボリックリンクされています。

また、~/がユーザー501によって所有されていることを示すls行に気付きました。これにより、同じ失敗がトリガーされます。

何が変わったかについての私の推測は、あなたのsshd_configStrictModesを指定するようになったということです。

2
aecolley