Примечание: это дубликатэтот вопрос StackOverflow, так как ali786 предположил, что здесь будет лучше.
Общая проблема
У меня есть компьютер (Mac OSX 10.9.4) и удаленный сервер (Ubuntu 14.04.1 LTS), к которому я подключаюсь по ssh как root. Я создавал ssh-keygen
ключ ssh (без парольной фразы), добавлял открытый ключ в сервер .ssh/authorized_keys
, и все было хорошо. Затем, сегодня утром, ssh
снова начали спрашивать пароль.
Что могло стать причиной этого?
Я действительно не уверен, что стало причиной этого — вот мои предположения:
- Мне пришлось удалить некоторые файлы из моего домашнего каталога на удаленном сервере, когда я случайно скопировал туда репозиторий git (я ничего не коммитил оттуда, просто скопировал и потом
rm
''вырезал). Насколько я могу судить по истории команд, я не удалил никаких файлов, имеющих отношение к 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:
Мне кажется странным, что он попытался использовать другой ключ SSH (otherkey_rsa) до того, который я указал ему использовать (mykey_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являетсяroot или его файлы .ssh являются символическими ссылками куда-то в /root
.
Кроме того, я заметил, что ваша строка ls показывает, что ~/
принадлежит пользователю 501. Это вызовет ту же ошибку.
Я предполагаю, что изменилось то, что sshd_config
теперь вы указываете StrictModes
.