SSHパスワードなしのログイン失敗のデバッグ体験を覚えておいてください

1.問題

sshのパスワードなしのログインを設定すると、一部のマシンが正常にログインしていて、一部のマシンはエラーメッセージを表示しました:ユーザーgzsunのサーバーでの公開鍵認証に失敗しました。ユーザー名と公開鍵/秘密鍵のペアを確認してください。


2.解決する

2.1 sshログの表示、デバッグ

ローカルで、sshクライアントを使用してログインします。

# ssh root@xxxx -p 2222 -v

sshサーバーで、ログを確認します。

# more /var/log/secure 

このうち、ユーザーの.sshフォルダーとユーザーのホームディレクトリ/ home / jackに権限がないことを示しています。

Authentication refused: bad ownership or modes for directory /home/jack/.ssh
Authentication refused: bad ownership or modes for directory /home/jack/.ssh
Authentication refused: bad ownership or modes for directory /home/jack/.ssh
error: Received disconnect from 36.111.140.26 port 59536:14: Unable to authenticate using any of the configured authentication methods.  [preauth]

Authentication refused: bad ownership or modes for directory /home/jack
Authentication refused: bad ownership or modes for directory /home/jack
Authentication refused: bad ownership or modes for directory /home/jack
error: Received disconnect from 36.111.140.26 port 62668:14: Unable to authenticate using any of the configured authentication methods.  [preauth]

/home/jack/.sshディレクトリは所有者ユーザーのみが読み取り、書き込み、実行できるため、他のユーザーはそれができず、
/ home / jack / .ssh / authorized_keysを読み取ることができず、ssh認証失敗します。 。


2.2ソリューション

解決策は非常に簡単です。関連するディレクトリのアクセス許可を確認し、要件を満たさないユーザーに必要なアクセス許可を設定します。

# chmod 700 /home/jack/

# chmod 700 /home/jack/.ssh

# chmod 600 /home/jack/.ssh/authorized_keys
# chown -R jack:jack /home/jack

注:ツールに関係なく、デバッグはドキュメントを読む必要があります。


3.参考記事

https://wiki.centos.org/HowTos/Network/SecuringSSH

おすすめ

転載: blog.csdn.net/yjk13703623757/article/details/107244403