Introduction to Enabling Password Authentication on EC2 Instances

Amazon Web Services (AWS) EC2 instances typically rely on key pairs for secure SSH access. However, there might be scenarios where enabling password authentication is necessary, such as for specific administrative tasks or when managing user access in a controlled environment. This guide will walk you through the steps to enable password authentication on your AWS EC2 instances, ensuring you balance convenience and security.

Why Enable Password Authentication on EC2?

While crucial pair authentication is the recommended and more secure method for accessing EC2 instances, there are situations where password authentication may be preferred or required. These include:

  • Temporary Administrative Access: Granting short-term access to administrators or team members who may not have access to the key pair.
  • Testing and Development: Setting up environments where quick and easy access is necessary without distributing key pairs.
  • User Management: In scenarios where multiple users need to access the instance but are not provided individual vital pairs.

Provisioning an EC2 Instance via AWS Console

Before enabling password authentication, you must have an EC2 instance running. Follow these steps to launch an EC2 instance via the AWS Management Console:

  1. Log in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. Click on “Launch Instance.”
  4. Choose an Amazon Machine Image (AMI), such as Amazon Linux 2.
  5. Select an Instance Type that fits your needs.
  6. Configure Instance Details, such as network and IAM role (if applicable).
  7. Add Storage to your instance as needed.
  8. Add Tags for better resource management.
  9. Configure Security Group: Ensure that SSH (port 22) is allowed.
  10. Choose an existing key pair, create a new one, and launch the instance.

SSH into the EC2 Instance Using Keypair

Once your instance is up and running, use the key pair to SSH into the instance:

  1. Open a terminal (or PuTTY on Windows).
  2. Navigate to the directory where your .pem file (key pair) is stored.
  3. Run the following command to SSH into your instance:
    ssh -i “your-key-pair.pem” ec2-user@your-ec2-instance-public-ip
  4. Accept the connection prompt if it’s your first time connecting to this instance.

Modifying SSH Configuration for Password Authentication

Now that you’re connected to your EC2 instance, you must modify the SSH configuration to allow password authentication.

Editing the SSH Configuration File

  1. Switch to the root user or use sudo to edit files with administrative privileges:
    sudo su
  2. Open the SSH configuration file using a text editor like vi or nano:
    nano /etc/ssh/sshd_config

Changing PasswordAuthentication Settings

Within the SSH configuration file:

  1. Locate the line that reads #PasswordAuthentication no.
  2. Uncomment the line by removing the # at the beginning.
  3. Change the value from no to yes so it reads:
    PasswordAuthentication yes
  4. Save the file and exit the editor (Ctrl + X in nano).

Restarting SSH Service and Setting the Password

To apply the changes:

  1. Restart the SSH service to load the new configuration:
    sudo systemctl restart sshd
  2. Set a password for the ec2-user (or another user):
    passwd ec2-user

You’ll be prompted to enter and confirm a new password.

Conclusion: Balancing Convenience and Security in EC2 Authentication

Enabling password authentication on your AWS EC2 instances can be helpful in specific scenarios, but it’s essential to be mindful of the security implications. Always ensure that solid and complex passwords are used, and consider disabling password authentication when it’s no longer needed. Key pair authentication remains the best practice for production environments due to its enhanced security features.

References

Get started with Amazon EC2

Manage system users on your Amazon EC2 Linux instance