Simplifying Access: Configuring Password Authentication for AWS EC2 Instances

Cloud Engineer | AWS Community Builder
Search for a command to run...

Cloud Engineer | AWS Community Builder
No comments yet. Be the first to comment.
You have a working Amazon EKS cluster and deployed pods. Now, your pods need secure, fine-grained access to AWS services like S3, DynamoDB, or Secrets Manager, but: You don't want to hardcode AWS cre

As your team and projects grow, managing a single EKS cluster can get complicated. You'll likely have different teams like a "Backend Team" and a "Frontend Team" all needing to deploy their applicatio

Serverless computing with AWS Lambda is one of the most powerful ways to run code in the cloud without managing servers. But when a Lambda function is placed inside a VPC (Virtual Private Cloud) to co

Modern developers want fast CI/CD but without storing long-lived AWS keys.By combining Amazon ECS (Fargate), Amazon ECR, GitHub Actions, and OpenID Connect (OIDC) you can deploy securely and automatic

Learn Bash Scripting: A Beginner's Guide Table of Contents Introduction Bash Scripting Basics Variables and User Input Conditional Statements Loops and Iterations Functions Working with Files Scripting Best Practices Conclusion 1. Introdu...

Enabling password authentication for AWS EC2 instances is a common requirement for users who prefer or need to use passwords instead of SSH key pairs for remote access. However, it's essential to note that using password authentication can introduce security risks, and AWS recommends using SSH key pairs for enhanced security. If you still need to enable password authentication, follow these steps carefully.
An AWS account with access to EC2.
An existing EC2 instance running a Linux-based operating system.
SSH access to your EC2 instance using a key pair.
Connect to Your EC2 Instance
First, you need to connect to your EC2 instance using SSH. Use the terminal (Linux/macOS) or an SSH client like PuTTY (Windows).
ssh -i /path/to/your-key.pem ec2-user@your-instance-public-dns
Replace /path/to/your-key.pem with the path to your SSH key, and ec2-user with your instance's appropriate username (e.g., ubuntu for Ubuntu instances).

2. Switch to the Root User
Once logged in, switch to the root user to ensure you have the necessary permissions to make configuration changes.
sudo su -

3. Edit the SSH Configuration File
Open the SSH configuration file using a text editor like vi or nano.
nano /etc/ssh/sshd_config

4. Modify SSH Configuration for Password Authentication
Find the following line in the sshd_config file:
PasswordAuthentication no
Change no to yes:
PasswordAuthentication yes

Additionally, ensure that the following line is uncommented and set to yes:
ChallengeResponseAuthentication no
5. Set a Password for the User
You need to set a password for the user you wish to enable password authentication for. For example, to set a password for the ec2-user, run:
passwd ec2-user

You'll be prompted to enter and confirm a new password.
6. Restart the SSH Service
To apply the changes, restart the SSH service:
service sshd restart

7. Update Security Groups (Optional)
Ensure your EC2 instance's security group allows inbound SSH (port 22) traffic. You can do this through the AWS Management Console:
Navigate to EC2 Dashboard > Instances.
Select your instance and click on the Security tab.
Click on the Security Groups link.
Add or ensure an inbound rule exists for SSH with Source set to your preferred IP range.
8. Test Password Authentication
Disconnect from the instance and attempt to reconnect using the password:
ssh ec2-user@your-instance-public-dns

Enter the password you set earlier when prompted.
Security Risks: Enabling password authentication increases the risk of brute-force attacks. Consider using complex passwords and limit the source IP range for SSH access.
Alternative Authentication: Consider using Multi-Factor Authentication (MFA) or a bastion host to improve security.
Logging and Monitoring: Enable logging and monitoring to detect unauthorized access attempts.
While enabling password authentication on AWS EC2 instances is straightforward, it is crucial to understand the security implications and follow best practices to mitigate potential risks. Whenever possible, prefer using SSH key pairs for secure and efficient authentication.
By following the steps outlined in this guide, you can enable password authentication on your EC2 instances and ensure you have proper security measures.