Published 9月 05, 2021 by with 0 comment

How to SSH from one AWS EC2 to another EC2?


I will share how to SSH from one Linux EC2 instance to another using the target EC2 instance's Private IP address.



1. Connect to EC2-1 from Windows using PuTTY "ec2-user@EC2-1-EIP"

[ec2-user@ip-10-200-33-43 ~]$

[ec2-user@ip-10-200-33-43 ~]$


2. The pwd command stands for print working directory.

[ec2-user@ip-10-200-33-43 ~]$ pwd

/home/ec2-user

[ec2-user@ip-10-200-33-43 ~]$

[ec2-user@ip-10-200-33-43 ~]$


3. The ls command allow a user to list files or directories from the CLI.

[ec2-user@ip-10-200-33-43 ~]$ ls

[ec2-user@ip-10-200-33-43 ~]$

[ec2-user@ip-10-200-33-43 ~]$


4. Using Notepad to open the testvm.pem in you local PC. Copy the all test.pem content.


6. In the EC2-1, use vi testvm.pem command means create a file called testvm.pem.

Paste all test.pem content to this new testvm.pem file.



[ec2-user@ip-10-200-33-43 ~]$ vi testvm.pem

[ec2-user@ip-10-200-33-43 ~]$

[ec2-user@ip-10-200-33-43 ~]$


7. Now, run ls command again, to check the file.

[ec2-user@ip-10-200-33-43 ~]$ ls

testvm.pem

[ec2-user@ip-10-200-33-43 ~]$


8. The chmod command allows you to change the permissions on a file using either a symbolic or numeric mode or a reference file.

[ec2-user@ip-10-200-33-43 ~]$ sudo chmod 400 testvm.pem

[ec2-user@ip-10-200-33-43 ~]$

[ec2-user@ip-10-200-33-43 ~]$


9.SSH to EC2-2 (10.200.32.137)

[ec2-user@ip-10-200-33-43 ~]$ ssh -i testvm.pem ec2-user@10.200.32.137


       __|  __|_  )

       _|  (     /   Amazon Linux 2 AMI

      ___|\___|___|


https://aws.amazon.com/amazon-linux-2/

[ec2-user@ip-10-200-32-137 ~]$

[ec2-user@ip-10-200-32-137 ~]$



Reference:

1. Convert your private key using PuTTYgen

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html


最初發表 / 最後更新: 2021.09.05 / 2021.09.05

0 comments:

張貼留言