DEV Community

Vansh Tyagi
Vansh Tyagi

Posted on

Can’t Login as Root on Ubuntu? Here’s the Real Reason and How to Fix It.

Introduction
If you’ve worked with CentOS or other RHEL-based systems, you're probably used to logging in directly as root no extra setup needed. But when you switch to Ubuntu, things are different. You try to login as root and get blocked. Even sudo su - might throw permission errors if you're not careful.
So what's going on here? Is it a bug? A restriction? No — it’s a security feature. Ubuntu disables direct root login by default to prevent unauthorized or accidental system damage. But if you're setting up a lab environment, testing on local, or just want full control here’s how you can enable root login on Ubuntu (safely and responsibly).

Steps to Enable Root Login in Ubuntu
Use this only in testing, learning, or non-production environments.

Step 1: Allow Root Login via SSH.
Open the SSH configuration file using a text editor.
sudo vi /etc/ssh/sshd_config
Find this line: PermitRootLogin prohibit-password
Change it to: PermitRootLogin yes
This line tells SSH that root login is now allowed using a password.

Step 2: Restart the SSH Service.
sudo systemctl restart ssh

Step 3: Set Root Password.
sudo passwd root

Step 4: Switch to Root User
su -
Here, You'll be prompted to enter the root password you set earlier.
Boom — you're now logged in as root.

Important
• Never enable root login on a public-facing production server.
• Use strong passwords if enabling this temporarily.
• Consider reverting the changes once you're done with your learning/test session.

Conclusion
Ubuntu disables root login by default not because it lacks the capability, but as a deliberate security measure. Once you understand this philosophy, you can confidently enable root access when needed and use it wisely.

Top comments (0)