Help us understand the problem. What is going on with this article?

同じVPC内のEC2へホスト名でSSH接続する

やりたいこと

前回の記事ではローカル端末からAWS上のEC2へホスト名でSSH接続しましたが、
今回は同じVPC内のEC2からEC2へホスト名でSSH接続します。

構成

rapture_20200122162137.png

AWSの設定

・test-bに対するインバウンド
 - TCPの22番ポートを許可
 - ソース:10.0.1.0/24

現状確認

設定前は以下のように、[test-a]から[test-b]へホスト名でSSH接続ができない

ubuntu@test-a:~$ ssh test-b
The authenticity of host 'test-b (10.0.2.100)' can't be established.
ECDSA key fingerprint is SHA256:************************************.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'test-b' (ECDSA) to the list of known hosts.
Permission denied (publickey).

test-aの設定

[~/.ssh]配下に[test.pem]という名前のファイルを作成し、秘密鍵ファイルを保管する

ubuntu@test-a:~/.ssh$ sudo vim test.pem

[~/.ssh]配下に[config]という名前のファイルを作成

ubuntu@test-a:~/.ssh$ sudo vim config

[config]ファイルに以下を記載する

Host test-b
 HostName 10.0.2.100
 User ubuntu
 Port 22
 IdentityFile ~/.ssh/test.pem

※[/etc/hosts]にtest-bのホスト名とIPアドレスが記載してあれば、「HostName」は記載不要

動作確認

ubuntu@test-a:~$ ssh test-b
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-1100-aws x86_64)
ubuntu@test-b:~$
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした