By default, AWS EC2 and Google Cloud instances disable root login and password authentication for security reasons. This guide shows how to enable root login on AWS EC2, but more importantly, explains when you should avoid it and use safer alternatives instead.
Table of Contents
Why Root Login Is Disabled on AWS and GCP
Cloud providers disable root login by default because it is a major security risk. Instead, they give you a standard user like ubuntu or ec2-user and require you to use sudo.
This approach:
• Prevents brute-force attacks on root
• Forces safer privilege escalation
• Reduces accidental system damage
This is considered best practice across modern infrastructure.
Should You Enable Root Login?
In most cases, no.
You should avoid enabling root login if:
• Your server is publicly accessible
• You are running production workloads
• You can use sudo instead
However, there are limited cases where it might be useful:
• Temporary debugging
• Certain automation workflows
• Legacy setups that require root access
VPSFix recommendation:
Do not enable root login unless you fully understand the risks.
Step 1: Switch to Root User
Log in using your default user and then switch to root:
sudo -i
Step 2: Edit SSH Configuration
Open the SSH config file:
nano /etc/ssh/sshd_config
Find:
PermitRootLogin
Change it to:
PermitRootLogin yes
Step 3: Enable Password Authentication (Optional)
Search for:
PasswordAuthentication no
Change it to:
PasswordAuthentication yes
⚠️ Enabling password login increases security risk significantly.
Step 4: Restart SSH Service
Apply changes:
sudo systemctl restart ssh
Step 5: Set a Root Password
Set a password for root:
passwd
You can now log in as root using SSH (if enabled) or Virtualmin URL.
Why This Is Risky
Enabling root login with password authentication exposes your server to:
• Brute-force attacks
• Unauthorized access attempts
• Full system compromise if breached
Even strong passwords are not enough protection.
Safer Alternative (Recommended)
Instead of enabling root:
• Use a sudo user
• Disable root SSH login
• Use SSH key authentication
• Limit access with firewall rules
This setup is both secure and practical.
Conclusion
While it is possible to enable root login on AWS EC2, it is rarely the right choice. Cloud providers disable it by default for a reason. Using a sudo-based workflow with SSH key authentication gives you the same control with much better security.
If you’re unsure how to manage root access safely, start with the recommended approach in the guide: How to Safely Use the Root User on a VPS.



