
注: これはこのStackOverflowの質問ali786 さんが、ここの方が良いと提案したので。
一般的な問題
私は自分のコンピューター (Mac OSX 10.9.4) とリモート サーバー (Ubuntu 14.04.1 LTS) を持っており、ルートとして SSH で接続しています。以前はssh-keygen
SSH キー (パスフレーズなし) を作成し、公開キーをサーバーの に追加していました.ssh/authorized_keys
が、すべて順調でした。しかし、本日早朝、ssh
再びパスワードを要求され始めました。
何が原因だったのか
何が原因なのかはよく分かりませんが、私の推測は次のとおりです。
- 誤って git リポジトリをリモート サーバーのホーム ディレクトリにコピーしてしまったため、いくつかのファイルを削除する必要がありました (そこからコミットしたりは何もせず、単にコピーして
rm
'd しただけです)。コマンド履歴から判断すると、削除したのは ssh 関連のファイルではなく、vim から残った .git、.gitignore、およびさまざまな *.sw? ファイルだけです。 - 私は
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:
使用するように指示した SSH キー (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
存在しないからだそうです。本当に存在するのでしょうか? もしそうなら、どうすれば作成できるのでしょうか?
本当に困惑しているので、助けていただけると嬉しいです。ありがとうございます!
答え1
auth.log
問題はまさにこれです。/root
所有者はremoteuserまたはroot以外のユーザーですが、ログインに不可欠なものです。remoteuserはルートまたはその .ssh ファイルは、 の下のどこかへのシンボリック リンクです/root
。
また、ls 行に、~/
ユーザー 501 が所有していることが示されています。これにより、同じ障害が発生します。
何が変わったかと言えば、sshd_config
今は を指定しているということですStrictModes
。