使用publickey的ssh登录仍然要求输入密码

时间:2019-12-19 10:36:05

标签: ssh

我已将公用密钥id_rsa.pub添加到远程/ home / user授权密钥。关于权限,该文件为600,父目录.ssh为700。我还修改了sshd_config。
当我执行ssh -vv user@remote时出现错误

debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/hjjj/.ssh/identity ((nil))
debug2: key: /home/hjjj/.ssh/id_rsa (0x55b3d8c54bc0)
debug2: key: /home/hjjj/.ssh/id_dsa ((nil))
debug2: key: /home/hjjj/.ssh/id_ecdsa ((nil))
debug3: Wrote 84 bytes for a total of 1309
debug1: Authentications that can continue: password,publickey
debug3: start over, passed a different list password,publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,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: Trying private key: /home/hjjj/.ssh/identity
debug3: no such identity: /home/hjjj/.ssh/identity
debug1: Offering public key: /home/hjjj/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 388 bytes for a total of 1697
debug1: Authentications that can continue: password,publickey
debug1: Trying private key: /home/hjjj/.ssh/id_dsa
debug3: no such identity: /home/hjjj/.ssh/id_dsa
debug1: Trying private key: /home/hjjj/.ssh/id_ecdsa
debug3: no such identity: /home/hjjj/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
123_hjjj@remote's password: 
debug3: packet_send2: adding 48 (len 65 padlen 15 extra_pad 64)
debug2: we sent a password packet, wait for reply
debug3: Wrote 148 bytes for a total of 1845.

---编辑--- 首先谢谢。我在下面进行了检查:我已经使用非root用户userA登录客户端,并且我想使用非root用户userB登录远程服务器,我可以使用密码身份验证成功访问该服务器。我还将用户A的id_rsa.pub添加到用户B的authorized_keys文件中。 sshd_config是----

# Authentication:

#LoginGraceTime 2m
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

我在/var/log下找不到auth.log,但在/var/log/secure下找不到。在客户端上执行ssh userB@remote -p 9998后,日志输出为:

sshd[22208]: Connection closed by 192.168.5.38

1 个答案:

答案 0 :(得分:0)

如果您在使用ssh时遇到问题,最好从-v开始使用ssh。
从您的日志中,您可以看到您提供了密钥(Offering public key: /home/hjjj/.ssh/id_rsa),
却不被接受(缺少Server accepts key

客户端的下一步应该是:

  • 验证您使用的是正确的用户
  • 验证您正在连接到预期的服务器

然后您应该切换到服务器:

  • 检查您的/etc/ssh/sshd_config中是否有PubkeyAuthentication yes
  • 检查/var/log/auth.log
  • 中的条目