Connection closed port 22 when connecting to Amazon AWS EC2 via ssh

By | March 12, 2020

If you are getting a connection closed on port 22 when trying to connect to Amazon AWS EC2 server via ssh, the chances are the user name you are using is wrong. If you are following the instructions at: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html for the first time and you are confused at:

ssh -i /path/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com

then you are not alone. You will have to change the command to refer to your own keypair.pem file. This part is easy. The “ec2-user” is valid for Fedora, RHEL and SUSE. If you are using Ubuntu, you’ll have to change the user to ubuntu. The full details are covered here.

The funky IP address at the end there can be copied from your dashboard. A screenshot would have saved me a bit of time too!

 

Note that this is a dynamic IP address allocation so if you terminate this instance and create a new one, this will change.

Category: AWS

Leave a Reply

Your email address will not be published.