SSH is a powerful tool for securely accessing and managing AWS EC2 instances, allowing developers and system administrators to log in, transfer files, and tunnel into private networks with encryption, while following best practices to keep their cloud infrastructure secure.
February 28, 2025
Photo by Shubham Dhage on Unsplash
Think of it as a secret tunnel that allows you to communicate with a machine safely, even if the internet around you is full of prying eyes.
Whether you're a developer, system admin, or just someone exploring cloud computing, SSH is a must-know tool—especially when working with AWS.
Imagine you have a computer sitting in a data center somewhere (like an AWS EC2 instance). You want to connect to it from your laptop at home.
Normally, sending login credentials over the internet would be risky, but SSH encrypts everything, making sure no one can snoop on your connection.
SSH runs on port 22 by default and works in a client-server model.
Your local machine (the client) requests a secure connection to the remote machine (the server), verifies its identity, and then lets you access it securely.
It’s like having a private, encrypted phone line to your AWS instance.
In AWS, SSH is mostly used to access EC2 instances (virtual servers in the cloud where you deployed your full-stack application).
When you launch an EC2 instance, AWS asks you to create or choose an SSH key pair.
This key acts like a special passcode that ensures only authorized users can log in.
Here’s how you connect to your EC2 instance from your terminal:
ssh -i /path/to/private_key.pem ec2-user@your-ec2-public-ip
Example: If your private key file is my-key.pem
and your EC2 instance has an IP of 3.12.45.67
, you’d run:
ssh -i my-key.pem ec2-user@3.12.45.67
If you're using an Ubuntu instance, replace ec2-user
with ubuntu
, and for Debian, use admin
.
1. Key Pair Authentication
AWS doesn’t use passwords for SSH by default. Instead, it uses key pairs. This makes hacking way harder because there’s no password to guess.
2. Bastion Hosts (Jump Servers)
Suppose your AWS instances are inside a private network, and you can’t access them directly.
You can set up a bastion host—a special EC2 instance that acts as a gateway. You SSH into the bastion, then hop into your private servers from there.
3. AWS Systems Manager Session Manager
Hate dealing with SSH keys? AWS offers Session Manager, which lets you connect to EC2 instances from the AWS console, no SSH required.
It’s great for security because you don’t even need to open port 22.
4. SSH Port Forwarding (Tunneling)
Let’s say you have a private database in AWS that can’t be accessed from the internet.
You can use SSH to tunnel into your AWS network and securely access that database from your local machine.
Example command:
ssh -i my-key.pem -L 3306:localhost:3306 ec2-user@3.12.45.67
This forwards your local port 3306 to the EC2 instance, allowing you to securely connect to a private MySQL database.
5. Secure File Transfer (SCP & SFTP)
Need to send files to your EC2 instance? Instead of messing with FTP, you can use SCP (Secure Copy Protocol):
scp -i my-key.pem myfile.txt ec2-user@3.12.45.67:/home/ec2-user/
This uploads myfile.txt
to your EC2 instance’s home directory.
To keep your AWS SSH connections secure:
Whether you're logging in, transferring files, or tunneling into private networks, SSH makes it all possible while keeping your data safe.
Now that you know how SSH works in AWS, give it a try.
Set up your SSH key, connect to your EC2 instance, and explore your cloud setup securely - Zen!