ssh-copy-idは成功しましたが、まだパスワードの入力を求められます。

ssh-copy-idは成功しましたが、まだパスワードの入力を求められます。
  1. 私はssh-copy-id root@c199以前これで成功しました。
  2. ssh root@c199パスワードプロンプトなしでログインできます
  3. 他のユーザーが自動的にログインしたいufo (リモートシステムにそのユーザーがいます)。
  4. 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.
    
  5. ただし、ログインすると、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

/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

ベストアンサー1

ありがとうhttps://unix.stackexchange.com/a/55481/106419、SSHをデバッグする方法を教えてくれます。

SSHデバッグを有効にして何が起こっているかを確認してください

systemctl stop sshd
/usr/sbin/sshd -d -p 22

私が見つけたもの:

Authentication refused: bad ownership or modes for directory /home/ufo

誰もが次のように言います。

  • /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をホームフォルダ名に変更します。

おすすめ記事