SSH 공개 키 로그인 시 이상한 동작

SSH 공개 키 로그인 시 이상한 동작

난 정말 여기에 갇혀있습니다. 공개 키를 사용하여 로컬에서 EC2 서버로 SSH를 통해 접속하려고 시도했지만 작동하지 않습니다. -> 권한이 거부되었습니다(공개 키).

설정은 다음과 같습니다. 로컬: 공개 키 쌍을 생성하고 id_rsa.pub의 내용을 복사합니다. 원격: PEM 파일을 사용하여 EC2 서버에 SSH로 접속하고 id_rsa.pub 내용을 .ssh 폴더에 있는 승인된 키 파일의 새 줄에 붙여넣었습니다.

제대로 작동해야합니까? 흔히 발생하는 실수가 권한이라는 것을 알았는데 내 권한은 올바르게 설정된 것 같습니다.

원격 권한:

drwx------ 2 ec2-user ec2-user  4096 Jul 23 04:00 .ssh

그리고 .ssh에서:

-rw-r--r-- 1 ec2-user ec2-user  404 Jul 24 03:19 id_rsa.pub
-rw------- 1 ec2-user ec2-user 1679 Jul 24 03:19 id_rsa
-rw------- 1 ec2-user ec2-user  529 Jul 26 20:53 authorized_keys

현지의:

drwx------    10 robvanhaaren  staff    340 Jul 26 18:43 .ssh

그리고 .ssh에서:

-rw-r--r--  1 robvanhaaren  staff   404 Jul 26 21:28 id_rsa.pub
-rw-------  1 robvanhaaren  staff  1766 Jul 26 21:28 id_rsa
-rw-r--r--  1 robvanhaaren  staff  5987 Jul 26 21:29 known_hosts

하지만 내가 실행할 때 :

Robs-MacBook-Air-2:.ssh robvanhaaren$ ssh ec2-54-85-62-99.compute-1.amazonaws.com -l ec2-user -v

그것은 다음을 반환합니다 :

OpenSSH_5.9p1, OpenSSL 0.9.8y 5 Feb 2013
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to ec2-54-85-62-99.compute-1.amazonaws.com [54.85.62.99] port 22.
debug1: Connection established.
debug1: identity file /Users/robvanhaaren/.ssh/id_rsa type 1
debug1: identity file /Users/robvanhaaren/.ssh/id_rsa-cert type -1
debug1: identity file /Users/robvanhaaren/.ssh/id_dsa type -1
debug1: identity file /Users/robvanhaaren/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 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 7a:d3:6c:7f:64:5d:b1:7b:2e:bb:73:0c:ce:0c:17:77
debug1: Host 'ec2-54-85-62-99.compute-1.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/robvanhaaren/.ssh/known_hosts:15
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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/robvanhaaren/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/robvanhaaren/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).

이상한 점은 다른 EC2 서버에서 공개 키를 사용하여 서버에 로그인할 수 있다는 것입니다.문제는 내 로컬 컴퓨터에 있는 것 같습니다., 리모컨이 아닙니다.

도와주세요!

답변1

SSH 문제는 번거로울 수 있습니다. 나는 항상 다음과 같이 시작합니다. 치트 시트에 명령이 저장되어 있으므로 오타를 두려워할 필요가 없습니다.

chmod 700 ~/.ssh && chmod 600 ~/.ssh/* \
&& chmod 644 ~/.ssh/authorized_keys \
&& chown -r <username>:<username> /home/<username>/.ssh \
&& chown -r <username>:<username> /home/<username>/.ssh/*

그래도 작동하지 않으면 Authorized_keys를 제거하고 다시 생성하여(소유권 및 권한에 주의) 메모장이나 다른 적절한 텍스트 편집기에서 내용을 복사했는지 확인합니다. 워드패드 및 기타 두꺼운 편집자는 키를 엉망으로 만들 수 있습니다. Known_hosts 파일에서 원격 호스트 항목을 제거할 수도 있습니다. 뭔가를 위해 한 번은 그랬던 기억이 나네요.

답변2

/var/log/auth.log댓글에 명시된 대로 꼭 확인해주세요 . 거의 항상 거기에서 답을 찾을 수 있습니다.

내 서버와 로컬에 대해 다음 권한이 설정되어 있습니다.

섬기는 사람

drwx------ remoteuser group ~/.ssh
-rw------- remoteuser group ~/.ssh/authorized_keys

장소 상에서

drwx------ user group ~/.ssh
-rw------- user group ~/.ssh/id_rsa
-rw----r-- user group ~/.ssh/id_rsa.pub

관련 정보