How to Setup Password less SSH Login on EC2 (Amazon Linux)

·

1 min read

Step 1: Generate an SSH Key Pair

ssh-keygen -t rsa -m PEM

After the keys are generated, you can check them using this command:

ls -lah ~/.ssh

You should see private key and public key.

cd ~/.ssh
cat id_rsa.pub  #for public key
cat id_rsa      #for private key

Step 2: Copy the Public Key to Your EC2 Instance

#for ubuntu instance
cat ~/.ssh/id_rsa.pub | ssh -i ~/path/to/your/key.pem ubuntu@your-ec2-public-ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

#for Amazon Linux Machine (I was using Amazon AMI)
cat ~/.ssh/id_rsa.pub | ssh -i ~/path/to/your/key.pem ec2-user@your-ec2-public-ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Step 3: Login to Your EC2 Instance Without a Password

ssh  ec2-user@your-ec2-public-ip