SSHアクセスを取得できません:「権限が拒否されました(公開鍵)」

SSHアクセスを取得できません:「権限が拒否されました(公開鍵)」

普通に使うテミウスMacからDebianサーバーにSSH経由で接続しましたが、これまではうまくいきました。今、私は好奇心が強いので、サードパーティが介入せずに内蔵のMac SSHクライアントを試してみました。

内容はこれです~/.ssh/config私のMacでは:

Host stalingrad
    Hostname xxx.xxx.xxx.xxx
    User root
    Port 22
    IdentityFile ~/.ssh/digital_ocean_id_rsa.pub
    IdentitiesOnly yes

私のMacを確認しました。~/.ssh/digital_ocean_id_rsa.pub私のDebianボックスと一致します。/root/.ssh/authorized_keys

また、VPS で次のコマンドを実行します。

$ chmod 700 /root/.ssh
$ chmod 600 /root/.ssh/authorized_keys 
$ /etc/init.d/ssh restart

さて、SSHを試してみましょう:

ssh [email protected]

私はこれを得た:

debug1: Will attempt key: /Users/andre/.ssh/id_rsa RSA SHA256:xxxxxxxxxxxxxxxx
debug1: Will attempt key: /Users/andre/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/andre/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /Users/andre/.ssh/id_ed25519 
debug1: Will attempt key: /Users/andre/.ssh/id_ed25519_sk 
debug1: Will attempt key: /Users/andre/.ssh/id_xmss 
debug1: Will attempt key: /Users/andre/.ssh/id_dsa 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: kex_input_ext_info: [email protected]=<0>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/andre/.ssh/id_rsa RSA SHA256:xxxxxxxxxxxxxxxx
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/andre/.ssh/id_ecdsa
debug1: Trying private key: /Users/andre/.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/andre/.ssh/id_ed25519
debug1: Trying private key: /Users/andre/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/andre/.ssh/id_xmss
debug1: Trying private key: /Users/andre/.ssh/id_dsa
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).

これが内容です/var/log/auth.logVPSから:

Oct 31 14:58:29 stalingrad sshd[249851]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:58:29 stalingrad sshd[249851]: Connection closed by xxx.xxx.xxx.xxx port 52960
Oct 31 14:58:50 stalingrad sshd[253607]: Connection closed by authenticating user root yyy.yyy.yyy.yyy port 60773 [preauth]
Oct 31 14:58:59 stalingrad sshd[254173]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:58:59 stalingrad sshd[254173]: Connection closed by xxx.xxx.xxx.xxx port 57792
Oct 31 14:59:27 stalingrad sshd[254174]: Received disconnect from yyy.yyy.yyy.yyy port 60774:11: Normal Shutdown [preauth]
Oct 31 14:59:27 stalingrad sshd[254174]: Disconnected from authenticating user root yyy.yyy.yyy.yyy port 60774 [preauth]
Oct 31 14:59:29 stalingrad sshd[254176]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:59:29 stalingrad sshd[254176]: Connection closed by xxx.xxx.xxx.xxx port 34386
Oct 31 14:59:49 stalingrad sshd[254177]: Connection closed by authenticating user root yyy.yyy.yyy.yyy port 60777 [preauth]
Oct 31 14:59:59 stalingrad sshd[254180]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:59:59 stalingrad sshd[254180]: Connection closed by xxx.xxx.xxx.xxx port 39216

SSHが指定された秘密鍵ファイルを読み取れなかったようです。number_ocean_id_rsa。代わりに、名前が「id_」で始まる秘密鍵ファイルの束を読み取ろうとします。どうなりますか?

ベストアンサー1

公開鍵をIdentityFileとして使用するSSHはありません。

公開鍵ファイル名ではなく秘密鍵ファイル名を使用する必要があります。

Host stalingrad
    Hostname xxx.xxx.xxx.xxx
    User root
    Port 22
    IdentityFile ~/.ssh/digital_ocean_id_rsa
    IdentitiesOnly yes

.ssh/config/IdentityFileで指定されたファイルは秘密鍵ですか、それとも公開鍵ですか?

おすすめ記事