ssh -i ~/.ssh/<instance-key>.pem ubuntu@<ec2-public-instance-ip>
You should log into the private ec2 from the private ip addess, which means you should log into public ec2 first. And then from there, log into the private ec2.
- Copy private key
cat ~/.ssh/<private-key-of-private-ec2>.pem | pbcopy
- Log into public ec2
- Create a pem.
vim ~/.ssh/<private-key>.pem
# :set paste in vim to paste private key
# :wq
- Log in
ssh -i ~/.ssh/<private-key>.pem ubuntu@<ec2-public-instance-ip>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/home/y/.ssh/.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/y/.ssh/.pem": bad permissions
If you get this error, run below:
chmod 0600 <instance-key>.pem