SSH Key Generation on AWS EC2

GURJAR VISHALGURJAR VISHAL
1 min read

Task: Generate a New SSH Key on an AWS EC2

Instance Instance OS: Amazon Linux

Task Objective: Generate a new RSA SSH key pair inside the EC2 instance

Step-by-Step Commands:

  1. SSH into the EC2 instance

ssh -i your-key.pem ec2-user@<ec2-public-ip>
  1. Verify you are inside the EC2

 whoami

Output: ec2-user

  1. Generate a new SSH key pair

ssh-keygen -t rsa -b 4096 -C "new-key-inside-ec2"

When prompted:

- Press Enter to accept default file location - Press Enter twice for no pass

Sample Output:

❖ Generating public/private rsa key pair.
❖ Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa): [Press Enter]
❖ Enter passphrase (empty for no passphrase): [Press Enter]
❖ Enter same passphrase again: [Press Enter]
❖ Your identification has been saved in /home/ec2-user/.ssh/id_rsa.
❖ Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub.

  1. List and verify SSH key files

ls -l ~/.ssh/

Expected Output: -rw------- 1 ec2-user ec2-user 3243 Jun 26 09:15 id_rsa

-rw-r--r-- 1 ec2-user ec2-user 743 Jun 26 09:15 id_rsa.pub

  1. (Optional) View the Public Key

 cat ~/.ssh/id_rsa.pub

Task Status: Completed Successfully

New SSH key pair generated at:

Private key: /home/ec2-user/.ssh/id_rsa

Public key: /home/ec2-user/.ssh/id_rsa.pub

0
Subscribe to my newsletter

Read articles from GURJAR VISHAL directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

GURJAR VISHAL
GURJAR VISHAL

Hey! I’m Vishal Gurjar, a passionate DevOps Engineer skilled in automating, deploying, and managing cloud-native applications. I specialize in tools like Docker, Kubernetes, Jenkins, AWS, Linux, and GitHub Actions — with hands-on experience building scalable CI/CD pipelines. Currently exploring and documenting my DevOps journey through real-world projects and tutorials. I believe in learning by doing and love sharing practical knowledge with the community. Let’s connect, build, and deploy the future — one container at a time. 🐳🚀