EC2 Linuxサーバー(公開鍵)でSSH権限が拒否されました。

EC2 Linuxサーバー(公開鍵)でSSH権限が拒否されました。

マスターからスレーブへのSSHを試みると、2つのUbuntu Linux EC2インスタンス(マスターとスレーブ)を作成しましたが、「許可拒否(公開鍵)」エラーが発生します。

サーバーの詳細

ubuntu@ip-172-31-41-115:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

私の日記

ubuntu@ip-172-31-41-115:~$ ssh -v [email protected]
OpenSSH_8.9p1 Ubuntu-3ubuntu0.6, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 172.31.39.155 [172.31.39.155] port 22.
debug1: Connection established.
debug1: identity file /home/ubuntu/.ssh/id_rsa type -1
debug1: identity file /home/ubuntu/.ssh/id_rsa-cert type -1
debug1: identity file /home/ubuntu/.ssh/id_ecdsa type -1
debug1: identity file /home/ubuntu/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/ubuntu/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/ubuntu/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/ubuntu/.ssh/id_ed25519 type -1
debug1: identity file /home/ubuntu/.ssh/id_ed25519-cert type -1
debug1: identity file /home/ubuntu/.ssh/id_ed25519_sk type -1
debug1: identity file /home/ubuntu/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/ubuntu/.ssh/id_xmss type -1
debug1: identity file /home/ubuntu/.ssh/id_xmss-cert type -1
debug1: identity file /home/ubuntu/.ssh/id_dsa type -1
debug1: identity file /home/ubuntu/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.6
debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 172.31.39.155:22 as 'ubuntu'
debug1: load_hostkeys: fopen /home/ubuntu/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
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: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:VXmUTrEoG6aXhqqnRZpg8RX4i7b8L5r0iAbyKtCmJwU
debug1: load_hostkeys: fopen /home/ubuntu/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '172.31.39.155' is known and matches the ED25519 host key.
debug1: Found key in /home/ubuntu/.ssh/known_hosts:1
debug1: ssh_packet_send2_wrapped: resetting send seqnr 3
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: ssh_packet_read_poll2: resetting read seqnr 3
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/ubuntu/.ssh/id_rsa
debug1: Will attempt key: /home/ubuntu/.ssh/id_ecdsa
debug1: Will attempt key: /home/ubuntu/.ssh/id_ecdsa_sk
debug1: Will attempt key: /home/ubuntu/.ssh/id_ed25519
debug1: Will attempt key: /home/ubuntu/.ssh/id_ed25519_sk
debug1: Will attempt key: /home/ubuntu/.ssh/id_xmss
debug1: Will attempt key: /home/ubuntu/.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: Trying private key: /home/ubuntu/.ssh/id_rsa
debug1: Trying private key: /home/ubuntu/.ssh/id_ecdsa
debug1: Trying private key: /home/ubuntu/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/ubuntu/.ssh/id_ed25519
debug1: Trying private key: /home/ubuntu/.ssh/id_ed25519_sk
debug1: Trying private key: /home/ubuntu/.ssh/id_xmss
debug1: Trying private key: /home/ubuntu/.ssh/id_dsa
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).

次の設定を使用して、/etc/ssh/sshd_config(マスターとスレーブ)ファイルを変更しました。

PermitRootLogin yes 
PubkeyAuthentication yes
 PasswordAuthentication yes 
GSSAPIAuthentication no 
GSSAPICleanupCredentials no

また、問題が発生した場合は、セキュリティグループのすべてのポートを開くことを許可しました。しかし、まだ同じ問題があります

ベストアンサー1

簡単な設定と簡単な認定IPでは、すべてのポートを開かずにパスワード認証を使用し、ルートログインを許可することを強くお勧めします。 2つのVMSが対話するためのものです。

これらの仮想マシンをどのように作成するのかわかりません。可能であれば、もう一度お試しください。構成の変更は最初から最小化されます。

AWSについてはよくわかりませんが、スレーブでプライベートキーを設定またはダウンロードする必要がありましたが、紛失した場合は次を参照してください。https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html#replacing-lost-key-pair

これをメインサーバーに送信し、まずアクセスを減らします。

chmod 400 .ssh/your_private_key.pem

確実にするために、事前にサーバーにpingを送信できることを確認してください。
またはAWS設定に戻って確認してください。

すべてが大丈夫に見え、サーバーが実行されている場合です。簡単なコマンドを試してみてください。

ssh -i .ssh/your_private_key.pem your_user@your_ip

明らかに、実際の名前にユーザーを変更します。確認するには、ユーザー名を2回確認してください。

それでも問題が解決せず、まだ AWS 経由でサーバーにアクセスできる場合は、次の点を確認してください。

  • ユーザーの本名
  • 次のコマンドを使用して SSH 構成を確認します。sshd -t
  • 構成の更新後、SSHデーモンが再ロードされたことsudo systemctl sshd reload、および起動されたことを確認してください。
  • インスタンスでファイアウォールが有効になっていることを確認する

これが基本的な概要です。私はまだセキュリティ上の考慮事項と今後のSSHingのための学習段階に戻って再度実行する必要があると思います。私にとっては、VMを起動するだけで/var/log/auth.logがめちゃくちゃになるので、これがあなたにどのような影響を与えるか想像できません。

この機能を使用するには、設定全体に関する追加情報を入手する必要があります。使用されているIPやホストなどの具体的な詳細は避けてください。

おすすめ記事