Linux

ssh 空白密碼,但仍然要求它

  • March 1, 2022

我創建了一個新使用者和密鑰,但是當我遠端訪問它時,它要求輸入密碼,但我沒有設置密碼。我也重做了三重檢查。以下是我執行的命令和錯誤。任何人都可以看到我創建密鑰的命令有任何明顯錯誤嗎?:

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).

你混合了很多東西。

您沒有為您創建的使用者設置密碼,因此它實際上無法使用密碼登錄,因此 SSH 不會要求輸入密碼。

但是,當您創建 SSH 密鑰時,您使用密碼保護了該密鑰。當它嘗試連接到伺服器時,它需要讀取該密鑰以驗證您的身份,從而要求輸入密鑰密碼。

此外,在您將密鑰添加到授權密鑰和嘗試連接之間,我錯過了幾個步驟,但它看起來(從事情的完成方式來看,日誌中沒有實際指示)就像您添加到的密鑰一樣授權密鑰不是您在嘗試連接的機器上擁有的密鑰。

引用自:https://serverfault.com/questions/845623