- Published on
SSH into AWS Instances the Lazy Engineer"s Way
cloud computing- Authors
- Name
- Ndamulelo Nemakhavhani
- @ndamulelonemakh
I have always found this way ssh ubuntu@ip
to be a better way to log in to my instances than ssh -i somefile.perm user@ip
(I know, it’s not that different, but I like what I like)
To my knowledge, the method using pem
files is the recommended way across most (AWS docs, probably for a good reason). But personally, I prefer to do it the way other clouds like Azure and GCP do it. Finally, I found a way to get this to work for AWS as well.
TLDR; So you want to go to key pairs and import a new key. instead of uploading a file just copy your public key and paste it instead. Now when you create your VM just ref your imported key, and then voila, you can SSH like the lazy Engineer that you are😉
Step-by-Step Guide
Step 1: Generate Your SSH Key Pair (If You Haven’t Already)
First things first, you need an SSH key pair. If you've been around the block a few times, you probably already have one. If not, it's easy to generate:
- Open your terminal.
- Run
ssh-keygen -t rsa -b 4096
to generate a new RSA key pair. - Follow the prompts to save your key pair and secure it with a passphrase.
This key pair will be your golden ticket to a smoother SSH experience.
I use this key for almost everything, Github, Other cloud dev instances etc. This is why I prefer the .
pem
-less SSH method because I only need to generate the key once.
Step 2: Import Your Public Key into AWS
Once you have your SSH key pair, the next step is to copy your public key into AWS. Here’s how:
- Log into your AWS Management Console and navigate to the EC2 dashboard.
- Under "Network & Security," find the "Key Pairs" section.
- Click on “Import Key Pair.”
- View the public key that you generated previously:
cat ~/.ssh/id_rsa.pub
- In the dialogue that appears, give your key pair a name and paste your public key into the designated field.
Step 3: Launching Your AWS Instance with the Imported Key
With your public key now cozy and warm in the AWS console, it’s time to put it to use:
- Go to the "Instances" section and click on “Launch Instances.”
- Choose your desired AMI (Amazon Machine Image) and instance type.
- When you reach the “Configure Instance” step, find the “Key Pair” dropdown.
- Select the key pair you imported earlier.
And just like that, you've laid the groundwork for SSH access without the tedious PEM file dance.
Step 4: SSH into Your Instance Like a Pro
ssh ubuntu@your-instance-ip
Replace ubuntu
with the appropriate user name for your AMI, and your-instance-ip
with your instance’s actual IP address. That's it. You're in—no -i
flag, no PEM file, just straight to business.
Why This Matters
This approach isn’t just about laziness (though that’s a perk). It’s about streamlining processes, reducing the overhead of managing multiple key files and bringing AWS in line with how other clouds handle SSH access. Now, when I write automation scripts I do not need to use special commands for AWS servers.
Disclaimer: I do not make any claim about the relative security posture of these two methods, I leave that in the hands of the experts.
Closing Thoughts
Congratulations! You’ve just upgraded your AWS SSH game. As always, I am happy to learn about your experiences in the comments below.