π The Landing Host Pattern: Secure Passwordless SSH Access
Hey Cloud Builders π
Welcome to Day 22 of the #100DaysOfCloud Challenge!
Today, weβre solving a real-world DevOps security problem for the Nautilus team enabling secure, passwordless SSH access from a landing host (aws-client) to a newly launched EC2 instance (devops-ec2).
By combining SSH key-based authentication with EC2 User Data, we can fully automate access from the very first boot π
π― Objective
- Launch a
t2.microEC2 instance - Generate an RSA key pair on the landing host
- Automatically configure root SSH access using User Data
- Enable passwordless authentication
π‘ Why SSH Keys & User Data Matter
Using passwords for SSH is risky and outdated. SSH keys provide stronger security and are essential for automation.
πΉ Key Concepts
Landing (Bastion) Host
Acts as a controlled entry point to your infrastructure for better auditing and security.-
EC2 User Data
A script that runs once at first boot, perfect for:- Installing packages
- Creating users
- Configuring SSH keys
Automation Benefit
No manual key copying. No human error. Scales effortlessly.
π οΈ Step-by-Step: Secure SSH Setup
Weβll move logically from the client β AWS β EC2.
πΉ Phase A: Generate SSH Key Pair (Landing Host)
On the aws-client, navigate to the SSH directory:
cd /root/.ssh
ssh-keygen -t rsa
Display and copy the public key:
cat /root/.ssh/id_rsa.pub
πΉ Phase B: Import Key Pair into AWS
Log in to the AWS Console and do the following:
- Open the AWS Management Console
- Navigate to EC2 β Network & Security β Key Pairs
- Click Import key pair
- Paste the public key generated on the landing host
- Click Import
πΉ Phase C: Launch EC2 with User Data Automation
EC2 Configuration
-
Name:
devops-ec2 -
Instance Type:
t2.micro - AMI: Ubuntu or Amazon Linux
User Data Script
Paste this under Advanced Details β User Data:
#!/bin/bash
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-rsa YOUR_PUBLIC_KEY_HERE" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart sshd
πΉ Phase D: Final SSH Hardening (Optional)
Some AMIs restrict root login by default.
- Log in as
ubuntuorec2-user - Switch to root:
sudo su -
- Ensure SSH config contains:
PermitRootLogin yes
- Restart SSH:
systemctl restart sshd
β Verify Passwordless Access
From the aws-client:
ssh root@<EC2_PUBLIC_IP>
π If you land directly in the root shell mission accomplished!
π Key Takeaways
- π User Data = Automation Superpower
- π SSH permissions must be exact (
700&600) - β οΈ Root login is okay for labs avoid in production
π« Common Mistakes
- Adding keys to the wrong user directory
- Breaking SSH with bad
sedsyntax - Uploading private keys instead of public ones
π Final Thoughts
You didnβt just launch an EC2
you automated secure access like a real Cloud Engineer πͺ
This pattern is foundational for:
- CI/CD pipelines
- Auto Scaling
- Zero-touch infrastructure
π Letβs Connect
- π¬ LinkedIn: Hritik Raj
- β GitHub: 100 Days of Cloud









Top comments (0)