EC2에서 사용자를 생성하려고 합니다. 수행한 단계는 다음과 같습니다.
root$ adduser abc --disabled-password
root$ sudo su abc
abc$ mkdir /home/abc/.ssh
abc$ chmod 700 /home/abc/.ssh
abc$ touch /home/abc/.ssh/authorized_keys
abc$ chmod 600 /home/abc/.ssh/authorized_keys
abc$ cat id_rsa.pub >> /home/abc/.ssh/authorized_keys
그런 다음 이 EC2에 사용자로 로그인하려고 시도했지만 다음 오류가 발생했습니다.
local$ ssh [email protected]
[email protected]: Permission denied (publickey).
그런 다음 시도했습니다.
local$ ssh [email protected] -vvv
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /Users/abc/.ssh/config
debug1: /Users/abc/.ssh/config line 33: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 45.121.95.191 port 22.
debug1: Connection established.
debug1: identity file /Users/abc/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/abc/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.10
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.10 pat OpenSSH_6.6.1* compat 0x04000000
debug3: fd 5 is O_NONBLOCK
debug1: Authenticating to 45.121.95.191:22 as 'abc'
debug3: hostkeys_foreach: reading file "/Users/abc/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/abc/.ssh/known_hosts:6
debug3: load_hostkeys: loaded 1 keys from 45.121.95.191
.
.
.
debug1: Host '45.121.95.191' is known and matches the ECDSA host key.
debug1: Found key in /Users/abc/.ssh/known_hosts:6
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 4294967296 blocks
debug2: key: /Users/abc/.ssh/id_rsa (0x7fa1a650aa30)
debug2: key: /Users/abc/.ssh/id_dsa (0x0)
debug2: key: /Users/abc/.ssh/id_ecdsa (0x0)
debug2: key: /Users/abc/.ssh/id_ed25519 (0x0)
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:aQVTb3WY7P8cEgl2CF5f0XOUDtDbOvgj1SMMwPNlSfg /Users/abc/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/abc/.ssh/id_dsa
debug3: no such identity: /Users/abc/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /Users/abc/.ssh/id_ecdsa
debug3: no such identity: /Users/abc/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/abc/.ssh/id_ed25519
debug3: no such identity: /Users/abc/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
심지어 같은 오류가 발생합니다.ssh -i /Users/abc/.ssh/id_rsa [email protected]
사용자 인증이 작동하지 않는 이유를 알고 싶습니다 /home/abc/.ssh/authorized_keys
. 누구든지 도와줄 수 있나요?
고쳐 쓰다:
이것도 /var/log/auth.log에서 가져온 것입니다.
Address ${MyPublicIP} maps to ${InternetProvider}, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Connection closed by ${MyPublicIP} [preauth]
답변1
서버에서 디버깅해야 하지만 SSH 클라이언트에서는 많은 것을 알 수 없습니다.
/etc/shadow에서 항목을 봅니다. 계정이 비활성화되었나요? 두 번째 필드는 "*"입니까, 아니면 "!"입니까?
편집하다:
로그에 따르면 DNS 확인 문제인 것 같습니다. DNS 검증은 해결하는 것보다 더 많은 문제를 일으킬 수 있습니다(현재는 아무도 로그인하지 않기를 바라지만 DNS 호스트 이름을 기반으로 로그인하지 않는 한).
/ etc /ssh/sshd_config에서 UseDNS no
.GSSAPIAuthentication no