ssh 密码为空但仍要求输入

Pet*_*son 6 linux debian ssh

我已经创建了一个新用户和密钥,但是当我远程访问时,它要求输入密码,但我没有设置密码。我还重做了三次检查。以下是我运行的命令和错误。任何人都可以看到我创建密钥的命令有任何明显的错误吗?:

useradd -m -d /home/webuser -s /bin/bash webuser
su webuser
ssh-keygen -t rsa
cat id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
rm id_rsa.pub

ssh webuser@ip_of_target_server
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/id_rsa ((nil)),
debug2: key: /root/.ssh/id_dsa ((nil)),
debug2: key: /root/.ssh/id_ecdsa ((nil)),
debug2: key: /root/.ssh/id_ed25519 ((nil)),
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list 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: /root/.ssh/id_rsa
debug1: key_parse_private2: missing begin marker
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/root/.ssh/id_rsa':
debug2: no passphrase given, try next key
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)

小智 3

你把很多事情搞混了。

您尚未为创建的用户设置密码,因此它实际上无法使用密码登录,因此 SSH 不会要求输入密码。

但是,当您创建 SSH 密钥时,您用密码保护了该密钥。当它尝试连接到服务器时,它需要读取该密钥来验证您的身份,因此需要密钥密码。

另外,我在将密钥添加到授权密钥和尝试连接之间缺少几个步骤,但它看起来(从事情的完成方式来看,日志中没有实际指示)就像您添加到授权密钥不是您尝试连接的计算机上拥有的密钥。