How to Setup SSH on EC2 Instances
I have created two EC2 instances on AWS. I created a key pair for each of them. I downloaded the .pem private keys and converted them into .ppk format. I can connect to each of my ec2 instances using PuTTY and their .ppk private key. But how do I SSH from one of my ec2 instance to the other? I can ping the Public DNS of either of them from the other. But if I try ssh from one to the other, I get:
Permission denied (publickey).
Setup SSH connection
On server A, run below command
Hit enter enter enter. You’ll have two files:
On Server A, cat and copy to clipboard the public key:
cat ~/.ssh/id_rsa.pub [select and copy to your clipboard]
Log onto server B, and add the public key from server A to authorized_keys file
vi ~/.ssh/authorized_keys [paste your clipboard contents] [save and close]
Now ssh from server A:
Repeat the process from server B to server A if you want to setup ssh connection in the opposite direction.