How to Connect to an EC2 Instance Using SSH
Tags: aws, programming, tutorial, devops
Published: 2023-06-19 18:42:51

Have you ever launched an EC2 instance and don’t know how to log in to your brand-new instance? It may sound difficult if you are a beginner, but it’s pretty much simple. Let’s take a look at how to connect to an EC2 instance using SSH, following the next simple steps whether you are using Linux or Windows.

---

## Requirements

- SSH Key (.pem file) provided by Amazon. This SSH key is provided by Amazon when you launch the instance.

- IP address. IP address assigned to your EC2 instance.

- Username. The username depends on the Linux distro you just launched. Usually, these are the usernames for the most common distributions:

-Ubuntu: ubuntu

-Amazon Linux: ec2-user

-Centos: root

**Only for Windows Users**
Putty SSH Client installed on your PC. You can download the latest version here: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

---



## How to connect to an EC2 instance using SSH using Linux

1.Open your terminal and change directory with command cd, where you downloaded your pem file. In this demonstration, pem file is stored in the downloads folder.

![connect to ec2 instance ssh using linux step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mziwehefu04mx8j5hnbt.png)



2.Type the SSH command with this structure:

`ssh -i file.pem username@ip-address
`   
This is the explanation of the previous command:

- ssh: Command to use SSH protocol
- -i: Flag that specifies an alternate identification file to use for public key authentication.
- username: Username that uses your instance
- ip-address: IP address given to your instance



3.After pressing enter, a question will prompt to add the host to your known_hosts file. Type yes. This will help to recognize the host each time you’re trying to connect to your instance.


![connect to ec2 instance ssh using linux step 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvkpazocylqo3d3g4a78.png)



4.And that’s it! Now you’re logged in on your AWS instance


![connect to ec2 instance ssh using linux step 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zc7tzy78t7xaim18x0h5.png)

---



## How to connect SSH into EC2 instance using SSH using Windows

1.Open your PuttyGen (it is included with your Putty Client installation) on your PC.


![connect ssh into ec2 instance using windows step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w76r2zfa2h9vsfydh4sr.png)


2.Make sure the checkbox “RSA” is selected.


![connect ssh into ec2 instance using windows step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rsatjl29jun6kbh6dg4g.png)


3.Click load and go to the folder where you have stored your pem file, select it and choose open.


![connect ssh into ec2 instance using windows step 3a](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ralv6qgwg35kvregs92p.png)


![connect ssh into ec2 instance using windows step 3b](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pjinrw6wfp8qlqlhsmp4.png)


4.You will see this message.

![connect to ec2 instance ssh using windows step 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bm103aqzm1dtjwrj0ysg.png)


Click OK


5.After the Key is loaded, click on save private key. Then a message will prompt, select yes.


![connect to ec2 instance ssh using windows step 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/roilhvg9xokwgws4c27x.png)


6.Now type a name for your key. For this example, the key will be named “instance” (it is not necessary to add the .ppk to the name file, Putty will do it)


![connect to ec2 instance ssh using windows step 6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5akhkfc4708jckdb9duo.png)


7.Now close PuttyGen program and open Putty. Go to SSH section and double-click it.


![connect to ec2 instance ssh using windows step 7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5zwjnthjrzdv09wypoa.png)


8.Go to Auth section and select the ppk file that we just created.


![connect to ec2 instance ssh using windows step 8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ld8mbxbrm61deyxlu8bc.png)


9.Go back at the top in the Session section. Fill the field Hostname (or IP address) with the IP address given to your AWS instance and click open.

![connect to ec2 instance ssh using windows step 9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpj08b6a6gu4xphddjc0.png)



10.A warning will prompt. The server host is not registered on our PC, so we must add it. Click yes.

![connect to ec2 instance ssh using windows step 10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x85dcsayoorkzdyo5ofb.png)


11.A window will prompt asking for the username, type your distro username, in this demonstration, username is ubuntu.


![connect to ec2 instance ssh using windows step 11](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2z79u17gg5n8sxuw6n6.png)


12.And there you go! Now you’re connected to your AWS instance using Putty on your Windows OS.


![connect to ec2 instance ssh using windows step 12](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0qayb9l46lx04zd1hrd.png)



You might also like: [What is AWS ECS? – Run Docker in Production](https://www.clickittech.com/aws/what-is-aws-ecs/?utm_source=devto&utm_medium=referal&utm_campaign=guest-posting&utm_content=text)

---



## Conclusion

As you can see, the steps are quite simple, but sometimes we can mess up the SSH conversion on Windows or how to get your instance information. In case that happens or you forget any step, feel free to come back and take a look at this tutorial on how to connect to EC2 instance ssh.

Now you will not be facing doubts the next time you launch your amazing AWS instances. Perhaps you want to take a look at how much you will spend on these brand-new instances; feel free to read [How AWS Pricing work](https://www.clickittech.com/aws/aws-pricing/?utm_source=devto&utm_medium=referal&utm_campaign=guest-posting&utm_content=text)s or read more awesome blogs on our website!

---



Original post from [ClickIT](https://www.clickittech.com/?utm_source=devto&utm_medium=referal&utm_campaign=guest-posting&utm_content=footer): https://www.clickittech.com/aws/connect-ec2-instance-using-ssh/?utm_source=devto&utm_medium=referal&utm_campaign=guest-posting&utm_content=footer