公開鍵を使用したSSHログインに失敗しました。

公開鍵を使用したSSHログインに失敗しました。

公開鍵を使用してcentos7を実行しているリモートサーバーに接続しようとしています。

キーを生成しました

ssh-keygen

次に、キーをサーバーにコピーします。

ssh-copy-id [email protected]

リモートシステムで作成されましたが、authorized_keysSSHログインにはまだパスワードが必要です。

トリプル詳細オプションを使用してログインしようとしました。

ssh -v [email protected]

それは私に次のようなものを与えます:

OpenSSH_7.6p1 Ubuntu-4ubuntu0.7, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to chip02.phy.ncu.edu.tw [140.115.32.12] port 22.
debug1: Connection established.
debug1: identity file /home/longhoa/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/longhoa/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/longhoa/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/longhoa/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/longhoa/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/longhoa/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/longhoa/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/longhoa/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to chip02.phy.ncu.edu.tw:22 as 'hoa'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:ALKc8EF9HMXaCSs/aN4wsfpFN8Bh1W9twUxOTueP5Kk
debug1: Host 'chip02.phy.ncu.edu.tw' is known and matches the ECDSA host key.
debug1: Found key in /home/longhoa/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)

debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:S79m96anBkvF16Rjihe80MYbcU1fZlfPxE5686k/vn4 /home/longhoa/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/longhoa/.ssh/id_dsa
debug1: Trying private key: /home/longhoa/.ssh/id_ecdsa
debug1: Trying private key: /home/longhoa/.ssh/id_ed25519
debug1: Next authentication method: password
[email protected] password: 
debug1: Authentication succeeded (password)

Googleで検索したところ、正しい権限の設定に関する言及があり、指示に従ってついに私のコンピュータでキーを見つけました。

-rw------- 1 longhoa longhoa 1.7K 23-01-08|14:14:40 id_rsa
-rw-r--r-- 1 longhoa longhoa  399 23-01-08|14:14:40 id_rsa.pub

リモートサーバーに対する権限:

drwx------. 2 hoa zh 4.0K 23-01-08|15:10 /home/hoa/.ssh
-rw-------. 1 hoa zh  399 23-01-08|14:23 /home/hoa/.ssh/authorized_keys
dr-xr-xr-x. 29 root root  4096 22-12-27|17:26 /
drwxrwxrwx. 41 root root  4096 22-11-24|18:38 /home
drwx------. 58 hoa  zh   12288 23-01-11|00:47 /home/hoa/

SELinuxに言及し、サーバーでデバッグする他の答えがありますが、そのサーバーへのrootアクセス権がないため、サーバーなしでは何もできません。

では、どのように機能させることができますか?とても感謝しています。


アップデート1

@roaimaの提案を試しました。

ssh -nvv -o NumberOfPasswordPrompts=0 [email protected] 2>&1 | grep "debug2: host key"

返品:

debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519

私もid_dsaとid_ed25519を試しましたが、どちらも機能しないようです。


アップデート2 @roaimaと@telcoMは、リモートホストの設定が間違っていることを指摘しました。管理者と通話後のステータスを更新します。

ベストアンサー1

私の考えでは、サーバー管理者がプライマリssh-rsaホストキーアルゴリズムを正確かつ賢明に無効にした可能性があります。これは、デフォルトの使用によってssh-keygenキーペアが無視されることを意味します。

クライアントで次のコマンドを実行してこれを確認できます。

ssh -nvv -o NumberOfPasswordPrompts=0 [email protected] 2>&1 | grep 'debug2: host key'

クライアントとサーバーの両方でサポートされている許容可能なホスト鍵アルゴリズムがリストされます。ssh-rsa(非常に良い)セキュリティ上の理由からサーバーで無効になっているため、このコマンド出力の2行目には表示されません。

たとえば、以下は私のローカルシステムでこのコマンドを実行した結果です。ssh-rsa最初の行(クライアント)にはリストされていますが、2番目の行(サーバー)にはリストされていないことがわかります。ホストキーアルゴリズムを使用するには、2行にリストする必要があります。

debug2: host key algorithms: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],ssh-ed25519,[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519

ssh-keygenこの場合、クライアントとサーバーの両方に存在するキータイプの特定のバリアントを使用する必要があります。次のキーペアは、デフォルトのRSAキーペアの代わりにED25519キーペアを生成します。

ssh-keygen -t ed25519

引用する

おすすめ記事