Mit*_*ril 5 password ssh authentication sshd
ssh-copy-id root@c199成功过。ssh root@c199没有密码提示的情况下登录ufo (远程机器有这个用户)ssh-copy-id ufo@c199 要求我输入密码,
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ufo@c199's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'ufo@c199'"
and check to make sure that only the key(s) you wanted were added.
Run Code Online (Sandbox Code Playgroud)但是登录ssh ufo@c199还是提示输入密码。
我尝试通过 ssh 在 msys2(在 Windows 上)上登录远程 centos,我发现有很多相同的行,例如
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs7RTfvn83Rxdmvgfh+F4kUlM5FzIUb9rRHaqq11xKIW1gztn/+G4tr+OWl4o6GTW2Z361hIi
ugy8DPtMATN66nTTDUYO0sSvw2BrQfDY4iIENdLpkkHO8KQVGpQE+8tDkaZfD6EQLVtl0uvDE3D77tfcnBLODXgZPQsUSlssMi+pxDbSVjjKgrP
hM1G/L9OTrEHKWDhF+ZBgY1RuLl7ZEdoATbhJaK4FFb9hNn/2CSibVfLts8HJGYQXIQRX/RBzaDZp47sKZvq302ewkkVorNY+c9mmoze6mi8Ip2
zEQOMi6S9zM/yRiD0XZrbmzYfNkoXA03WTmMR/DynVvX2nV /c/Users/xxxx/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
在 centos 中/home/ufo/.ssh/authorized_keys,
我已将 .ssh 用户的文件夹权限更改为 700 ,并将 authorized_keys 文件更改为 644 。
相同的 ssh 密钥,ssh root@c199无ssh ufo@c199提示登录,但提示输入密码..
ssh ufo@c199 -vv 输出:
....
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:zmCg5vHhBAMd5P4ei82+KsVg072KXbC63C44P0w3zbU
debug1: Host 'c199' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/xxxxx/.ssh/known_hosts:35
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug2: key: /c/Users/xxxxx/.ssh/id_rsa (0x60006bec0), agent
debug2: key: /c/Users/xxxxx/.ssh/id_dsa (0x0)
debug2: key: /c/Users/xxxxx/.ssh/id_ecdsa (0x0)
debug2: key: /c/Users/xxxxx/.ssh/id_ed25519 (0x0)
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/xxxxx/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /c/Users/xxxxx/.ssh/id_dsa
debug1: Trying private key: /c/Users/xxxxx/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/xxxxx/.ssh/id_ed25519
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
Run Code Online (Sandbox Code Playgroud)
感谢https://unix.stackexchange.com/a/55481/106419,它告诉我如何调试 ssh。
启用 ssh 调试以查看发生了什么
systemctl stop sshd
/usr/sbin/sshd -d -p 22
Run Code Online (Sandbox Code Playgroud)
我发现:
Authentication refused: bad ownership or modes for directory /home/ufo
Run Code Online (Sandbox Code Playgroud)
大家只说:
/home/ufo/.ssh 所有权正确 700/home/ufo/.ssh/authorized_keys 所有权正确 600/644但是 sshd 仍然检查用户主文件夹!!!没有人提到这一点!
sudo chmod 700 /home/ufo 解决这个问题。
概括:
您需要确保:
/home/ufo 所有权是 700/home/ufo/.ssh 所有权是 700/home/ufo/.ssh/authorized_keys 所有权是 600将 ufo 更改为您的主文件夹名称
| 归档时间: |
|
| 查看次数: |
16999 次 |
| 最近记录: |