참고: 이것은 다음과 중복됩니다.이 StackOverflow 질문, ali786이 여기가 더 나을 것이라고 제안했기 때문에.
일반적인 문제
내 컴퓨터(Mac OSX 10.9.4)와 루트로 SSH를 통해 접속하는 원격 서버(Ubuntu 14.04.1 LTS)가 있습니다. 저는 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:
내가 사용하라고 지시한 것(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
원격 사용자 또는 루트가 아닌 사용자가 소유하고 있지만 로그인에 필수적입니다. 원격 사용자~이다루트 또는 해당 .ssh 파일은 /root
.
또한 ~/
사용자 501이 소유하고 있음을 보여주는 ls 행이 표시됩니다. 이로 인해 동일한 오류가 발생합니다.
변경된 사항에 대한 내 추측은 귀하가 sshd_config
이제 지정 한다는 것입니다 StrictModes
.