新用户的 ssh 失败,权限被拒绝(公钥)

新用户的 ssh 失败,权限被拒绝(公钥)

我正在尝试在 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

相关内容