How to Enable Root Access on EC2 Instance/Any Server

How to Enable Root Access on EC2 Instance

Share This Post

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:

  1. Sign in to the AWS Management Console and navigate to the EC2 dashboard.
  2. Click on “Launch Instance” to create a new EC2 instance.
  3. Choose an Amazon Machine Image (AMI), instance type, and configure other instance settings according to your requirements.
  4. In the “Configure Security Group” step, ensure that SSH (port 22) is open to your IP address or a specific range for secure access.
  5. 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:

  1. Open your terminal or SSH client.
  2. Navigate to the directory where your private key file (.pem) is located.
  3. Use the following command to connect to your EC2 instance:

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:

  1. Connect to your EC2 instance via SSH as the default user (ec2-user or ubuntu depending on the Linux distribution).
  2. Switch to the root user using the following command:

Step 4: Set a Password for the Root User

Once logged in as the root user, set a password using the following command:

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:

  1. Open the SSH configuration file for editing:
  1. Find the line that says PasswordAuthentication no and change it to PasswordAuthentication yes.
  2. Find the line that says PermitRootLogin without-password and change it to PermitRootLogin yes.
  3. Save the changes and exit the editor.

Step 6: Restart SSH Service

To apply the changes, restart the SSH service:

  1. Restart the SSH service using the following command:

Step 7: Test Root User Access with Password Authentication

Once the SSH service is restarted, you can test root user access with password authentication:

  1. Open a new terminal window or SSH client.
  2. Connect to your EC2 instance as the root user using the following command:
  1. 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!

Share this post:

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

How to Enable Root Access on EC2 Instance

Share This Post

Share this post:

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Do You Want To Boost Your Business?

drop us a line and keep in touch

small_c_popup.png

Share your details to letus know about your needs!

Let's have a chat