Table of Contents
Introduction
How to Enable Root Access on EC2 Instance: Welcome, cloud adventurers! Today, we’re delving into the world of AWS EC2 instance (works on other servers also like on GCP) to uncover the secrets of enabling root user access and password authentication. By default, AWS EC2 instances grant access via SSH key pairs for enhanced security. However, there are scenarios where enabling root user access with password authentication becomes necessary. Fear not, as we’ll walk you through the process step by step in this comprehensive tutorial.
Introduction to AWS EC2 Root Access and Password Authentication
Amazon EC2 instances provide scalable compute capacity in the cloud, offering a wide range of configuration options to meet your specific requirements. By default, EC2 instances allow SSH access using key pairs for authentication, providing a secure method for accessing your instances. However, in certain situations, such as troubleshooting or legacy application compatibility, enabling root user access with password authentication may be required.
Step 1: Launch Your EC2 Instance
Before enabling root user access and password authentication, you’ll need to launch an EC2 instance:
- Sign in to the AWS Management Console and navigate to the EC2 dashboard.
- Click on “Launch Instance” to create a new EC2 instance.
- Choose an Amazon Machine Image (AMI), instance type, and configure other instance settings according to your requirements.
- In the “Configure Security Group” step, ensure that SSH (port 22) is open to your IP address or a specific range for secure access.
- Review your instance configuration and launch your EC2 instance.
Create an EC2 Instance and Install LAMP Stack on AWS : Step By Step
Step 2: Connect to Your EC2 Instance via SSH
Note: From now on, all steps given are applicable on all cloud servers, Google Cloud/Azure/Oracle cloud etc.
Once your EC2 instance is running, you’ll need to connect to it via SSH using the private key associated with your key pair:
- Open your terminal or SSH client.
- Navigate to the directory where your private key file (.pem) is located.
- Use the following command to connect to your EC2 instance:
ssh -i your-private-key.pem ec2-user@your-instance-public-ip
Replace your-private-key.pem
with the name of your private key file and your-instance-public-ip
with the public IP address of your EC2 instance.
Step 3: Enable Root User Access
By default, the root user is disabled on AWS EC2 instances. To enable root user access:
- Connect to your EC2 instance via SSH as the default user (
ec2-user
orubuntu
depending on the Linux distribution). - Switch to the root user using the following command:
sudo su
Step 4: Set a Password for the Root User
Once logged in as the root user, set a password using the following command:
passwd
You’ll be prompted to enter and confirm the new password for the root user.
Step 5: Enable Password Authentication in SSH Configuration
To allow password authentication for SSH, modify the SSH configuration file:
- Open the SSH configuration file for editing:
nano /etc/ssh/sshd_config
- Find the line that says
PasswordAuthentication no
and change it toPasswordAuthentication yes
. - Find the line that says
PermitRootLogin without-password
and change it toPermitRootLogin yes
. - Save the changes and exit the editor.
Step 6: Restart SSH Service
To apply the changes, restart the SSH service:
- Restart the SSH service using the following command:
systemctl restart sshd
Step 7: Test Root User Access with Password Authentication
Once the SSH service is restarted, you can test root user access with password authentication:
- Open a new terminal window or SSH client.
- Connect to your EC2 instance as the root user using the following command:
ssh root@your-instance-public-ip
- Enter the password you set earlier when prompted.
Congratulations! You’ve successfully enabled root user access and password authentication on your AWS EC2 instance. You now have full administrative control over your instance using the root user and password authentication method.
Conclusion
In this tutorial, we’ve walked you through the process of enabling root user access and password authentication on an AWS EC2 instance. While SSH key pairs provide a secure method for accessing EC2 instances, enabling root user access with password authentication can be useful in certain scenarios. Remember to exercise caution when enabling root user access and ensure that strong passwords are used to enhance security.
Happy cloud computing, and may your EC2 adventures be secure and seamless!