How to Create SSH Passwordless Login to AWS EC2

How to Create SSH Passwordless Login to AWS EC2

SSH passwordless login provides a secure and efficient way to access your AWS EC2 instances without the need for constantly entering a password. This not only enhances the user experience but also strengthens the security of your infrastructure. In this guide, we will walk through the step-by-step process of setting up SSH passwordless login to AWS EC2 instances.


Before we begin, make sure you have the following prerequisites:

  1. An AWS account with at least one EC2 instance.
  2. A local machine from which you will initiate the SSH connection.

Step 1: Connect to your AWS EC2 instance

Open your terminal and use the following command to connect to your EC2 instance. Replace your-instance-ip with the actual IP address of your EC2 instance and your-key.pem with the path to your private key file.

ssh -i your-key.pem ec2-user@your-instance-ip

Step 2: Generate SSH Key Pair

On your local machine, if you haven't already generated an SSH key pair, do so using the following command:

ssh-keygen -t rsa -b 2048

This will create a new SSH key pair (public and private keys) in the default location (~/.ssh/id_rsa).

Step 3: Copy the Public Key to your AWS EC2 instance

Use the following command to copy the public key to your EC2 instance. Replace your-key.pem and your-instance-ip accordingly.

scp -i your-key.pem ~/.ssh/ ec2-user@your-instance-ip:~/

Step 4: Log in to your EC2 instance

Now, log in to your EC2 instance using SSH.

ssh -i your-key.pem ec2-user@your-instance-ip

Step 5: Configure Passwordless Login

Once logged in, concatenate the public key to the authorized_keys file to enable passwordless login.

cat >> ~/.ssh/authorized_keys

Step 6: Adjust Permissions

Set the correct permissions for the .ssh directory and the authorized_keys file.

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Step 7: Test Passwordless Login

Exit the current SSH session and try logging in again. You should now be able to log in without entering a password.

ssh -i your-key.pem ec2-user@your-instance-ip

Congratulations! You have successfully set up SSH passwordless login to your AWS EC2 instance.

Additional Tips:

  • Rotate Keys: Consider rotating your SSH keys periodically for enhanced security.
  • Disable Password Authentication: For added security, disable password authentication in the SSH configuration file (/etc/ssh/sshd_config).

Related Searches and Questions asked:

  • How to Configure AWS Lambda Reserved Concurrency?
  • How to Transfer Data to S3 Bucket from Local Folders
  • Linux Commands Cheat Sheet
  • How to Send Mail using Gmail Credentials on Ubuntu?
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.