AWS: EC2 Linux Instance – Connect using SSH from your Windows PC
When creating the Instance, select a public subnet if you have a mix of private and public within the VPC. If not, you will not be able to connect regardless if you enable the public IP
To connect to your Amazon Web Services (AWS) EC2 Linux instance using Secure Shell (SSH) from a Windows machine, you would typically use a program like PuTTY or Windows Subsystem for Linux (WSL). Here’s how you do it with both:
1. Using PuTTY:
Before you start, make sure you have the following:
- The PuTTY program is installed on your Windows computer. You can download it from the PuTTY website.
- Your EC2 Instance’s public DNS or public IP address. You can find this on the EC2 console under the “Instances” section.
- The private key file (.pem) that you got when you launched your instance. If you don’t have this, you won’t be able to connect.
Here are the steps:
- Convert your .pem file to a .ppk file that PuTTY can use. You can do this with PuTTYgen, which comes with PuTTY. Just open it, click “Load” to load your .pem file, and then click “Save private key” to save the .ppk version.
- Open PuTTY.
- In the “Host Name (or IP address)” box, put in
ec2-user@your_public_dns
orec2-user@your_public_ip
. Theec2-user
part is the default user that AWS sets up for you. - In the “Category” list on the left, go to Connection > SSH > Auth.
- In the “Private key file for authentication” box, click “Browse” and find the .ppk file you saved earlier.
- Go back to the “Session” category and click “Open” to start your SSH session.
2. Using Windows Subsystem for Linux (WSL):
If you’re using WSL, the process is more similar to doing it on a Linux machine. Again, make sure you have your instance’s public DNS or public IP, and your .pem file.
Here are the steps:
- Open your WSL terminal.
- Navigate to the folder that has your .pem file. For example, if it’s in your Documents folder, you’d use
cd /mnt/c/Users/YourUsername/Documents
. - Change the permissions of your .pem file so it’s not publicly viewable:
chmod 400 your_file.pem
. - Connect to your instance with the ssh command:
ssh -i your_file.pem ec2-user@your_public_dns
orssh -i your_file.pem ec2-user@your_public_ip
.
You should now be connected to your EC2 Linux instance. If you run into any issues, make sure your instance is actually running, that you’re using the right public DNS or public IP, and that your .pem file is correct.