Connect to EC2 Instances With SSH

How to connect to Amazon EC2 instances via SSH.

1315 views

Edited: 2019-12-15 12:22

You can connect to EC2 with SSH to remote control your server, install updates, and do other maintenance work. You would also use SSH when installing a web server, such as Apache.

When first connecting, it is important that your key file has the right permissions. This is often a problem when connecting from a Linux terminal, because people simply forget about it. If you are either connecting for the first time, or have moved your file since last time, then you may need to change the permissions. This is easy:

sudo chmod 400 /home/YourUserName/keyfiles/YourKeyFile.pem

Another common problem when connecting, is that we forget our username for EC2. When we connect to the server, we should append the Public DNS with ubuntu@. Example below:

ssh -i /home/YourUserName/keyfiles/YourKeyFile.pem [email protected]

The Public DNS part in the above is the part after the @, and it will be different for your server. If you do not know the Public DNS of your server, you can easily find it by logging into your account on aws.amazon.com

If these instructions are unclear, you can also watch the video embedded last in the tutorial. Note that there may be minor differences in the AWS website, if it has been updated since the video was recorded.

Connecting via SSH from Windows

If you are on Windows, you will need to either use the build-in SSH capabilities (Linux services for Windows), or use a program, such as Putty, to connect.

The procedure should be the same as the above, and you will be able to perform the same actions after logging in.

You can get the latest version of Putty here: http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Video

Tell us what you think:

  1. In this article I will explain how to enable a swapfile on small instances, and why it might be useful, even if you do have enough physical memory.
  2. With some network configurations, TLS/SSL might break when relaunching an EC2 instance from an AMI backup.
  3. How to configure a SMTP server with letsencrypt on an amazon EC2 instance.
  4. How to have multiple public IPs with one AWS EC2 Instance
  5. If you suddenly can not connect to your server in the cloud for no apparent reason, it may be because it is running out of physical memory. In this article, I will discuss a few solutions to this problem.

More in: AWS