私は持っている2 インスタンスAWSで。そのうちの1つはパブリックサブネット(要塞)、2番目のプライベートサブネット。
どちらも同じキーペアで起動されました(.pemファイル)。
要塞に接続する方法は次のとおりです。
ssh -i secret.pem ec2-user@public-ip
素晴らしいです、参加します。
ここで、プライベートサブネット内のインスタンスに ssh で接続したいと思います。Google で調べたところ、エージェントを転送する必要があるようです。
ssh -A ubuntu@private-ip
しかし残念ながら、次のエラーが発生します:
Permission denied (publickey).
何が間違っているのか、またプライベートインスタンスに SSH で接続するにはどうすればよいのか、誰か説明してもらえますか? (ping とセキュリティグループは問題ありません)
答え1
私ならこうします:
自分のラップトップで、~/.ssh/config を作成 (または既存のファイルを編集) し、以下を追加します。
Host [host or ip of the bastion server]
User ec2-user
IdentityFile ~/.ssh/pem_file_required_to_connect_to_bastion
Host [host or ip of the bastion server]
User ec2-user
IdentityFile ~/.ssh/pem_file_required_to_connect_to_server
ProxyCommand ssh ec2-user@CHOSEN_HOST -W %h:%p
CHOSEN_HOST を、要塞サーバー用に構成したのと同じホストに置き換えます。
例:
cat ~/.ssh/config
Host 3.126.138.136
User ec2-user
IdentityFile ~/.ssh/itaig.pem
Host 172.31.22.212
User ec2-user
IdentityFile ~/.ssh/itaig.pem
ProxyCommand ssh [email protected] -W %h:%p
~/.ssh at 02:40:57 PM
❯
ssh 172.31.22.212
Last login: Sun Aug 8 11:40:41 2021 from ip-172-31-29-253.eu-central-1.compute.internal
__| __|_ )
_| ( / Amazon Linux 2 AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-2/
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
[ec2-user@ip-172-31-22-212 ~]$