How to Enable and Disable Root User Account in Ubuntu
Learn how to enable and disable root user account in ubuntu 24.04 safely with passwd locking, SSH PermitRootLogin policies, and sudo -i workflows.

5 min read
Learn how to enable and disable root user account in ubuntu 24.04 safely with passwd locking, SSH PermitRootLogin policies, and sudo -i workflows.
- Prerequisites and Supported Releases
- Understanding the Ubuntu Root Account Security Model
- Step 1: How to Enable the Root User Account
On traditional UNIX and Linux operating systems, system administration is performed by logging in directly as the root user.
However, Ubuntu departs from this conventional model by purposefully disabling the root user password by default upon system installation.
In the system shadow database (/etc/shadow), the root account is marked with an exclamation point (!), rendering direct password-based logins impossible.
Instead, Ubuntu delegates full administrative capabilities to members of the sudo group, providing accountable audit logging and preventing automated root brute-force attacks.
In this guide, we explain how to enable and disable root user account in ubuntu, configure SSH root restrictions, and adopt the modern sudo -i workflow.
Essential Linux security tutorial on managing the root superuser account on Ubuntu 24.04 LTS and 22.04 LTS. Explains why Ubuntu locks the root account by default with an invalid password hash, how to set a root password when necessary, how to lock it again with passwd -l, how to block SSH root login, and how to use sudo -i as the secure alternative.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A computer or server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- An unprivileged user account with
sudoadministrative privileges. - Access to a terminal shell or SSH console.
- Understanding of password security standards.
Understanding the Ubuntu Root Account Security Model
A common misconception among new Linux administrators is that Ubuntu has deleted or removed the root account.
The root account exists on every Ubuntu installation with UID 0, but it has no assigned password hash.
Inspect the root account entry in /etc/shadow to observe the default locked state:
The ! symbol indicates that the password hash field cannot match any encrypted password string:
# Inspect the root account shadow entry:
sudo grep '^root:' /etc/shadow
# Default output:
# root:!:19800:0:99999:7:::
# Notice the exclamation mark (!) in the second field.
# This signifies an account with a locked password.
Step 1: How to Enable the Root User Account
Certain legacy software suites, specialized hypervisors, or single-user rescue environments require an active root password.
To enable the root account, assign it a secure password using the passwd command with sudo escalation:
Enter and confirm a strong, high-entropy password for the superuser:
# Set a password for the root superuser:
sudo passwd root
# Terminal prompt:
# New password:
# Retype new password:
# passwd: password updated successfully
# Verify the shadow entry now contains a valid cryptographic hash (e.g. $y$):
sudo grep '^root:' /etc/shadow
# Output: root:$y$j9T$ABC123xyz...:19800:0:99999:7:::
Testing Root Login via su
With a password assigned, you can switch directly to the root user session using the standard su (substitute user) utility:
Enter the newly created root password to open an interactive superuser shell:
# Switch to root user shell:
su -
# Enter root password.
# Verify active session identity:
whoami
# Output: root
Step 2: How to Disable the Root User Account
Once maintenance tasks or emergency recovery operations are complete, re-locking the root password restores Ubuntu's standard security posture.
Use the passwd utility with the -l (lock) option:
This prepends an exclamation point to the encrypted hash, immediately disabling password logins while preserving SSH key authentication if configured:
# Lock the root account password:
sudo passwd -l root
# Output: passwd: password expiry information changed.
# Verify the locked status in /etc/shadow:
sudo grep '^root:' /etc/shadow
# Output: root:!$y$j9T$...:19800:0:99999:7:::
# Test that direct su login is now rejected:
su -
# Output: su: Authentication failure
Step 3: Disabling Root Login over SSH (/etc/ssh/sshd_config)
Even when the root account has a password enabled locally, exposing direct root logins over SSH presents extreme security vulnerabilities to internet scanners.
Harden the OpenSSH server daemon by configuring PermitRootLogin in /etc/ssh/sshd_config:
Set the directive to no (or prohibit-password for key-only access):
# Update SSH configuration to forbid direct root login:
sudo sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
# Verify configuration syntax:
sudo sshd -t
# Restart the OpenSSH service daemon:
sudo systemctl restart ssh
Step 4: The Recommended Alternative: sudo -i and sudo -s
You do not need to enable the root account to obtain a persistent superuser shell.
Ubuntu provides clean command-line alternatives that grant root shell access using your personal account password:
Review this comparison of interactive root shell techniques:
| Command | Shell Environment | Working Directory | Recommended Use Case |
|---|---|---|---|
sudo -i | Simulates a full login shell; loads root's .profile and .bashrc | Switches to /root | Standard administration when full root environment is required |
sudo -s | Starts a shell using the current user's environment variables | Retains current working directory | Quick multi-command operations without path changes |
sudo [command] | Executes a single command with root privileges and exits | Retains current working directory | Best practice for daily system administration |
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
Authentication failure when attempting su - with root password
Cause: The root account password was locked using passwd -l or was never initialized.
Resolution: Use sudo passwd root from an authorized sudoer account to assign a new password.
sudo passwd root
Permission denied (publickey,password) when logging into SSH as root
Cause: PermitRootLogin no is enforced in /etc/ssh/sshd_config.
Resolution: Log in using your non-root sudoer account and elevate privileges with sudo -i.
ssh username@server-ip
Cannot execute sudo commands after modifying root settings
Cause: User accidentally removed themselves from the sudo group.
Resolution: Reboot into Ubuntu Recovery Mode from GRUB, select 'root - Drop to root shell prompt', and run usermod -aG sudo username.
usermod -aG sudo username
Security Best Practices and Hardening
Keeping the root account locked is the single most effective way to eliminate automated dictionary attacks targeting user 'root'.
Always verify that your non-root user has working sudo access in a separate terminal before locking or unlocking root.
Review privileged audit events in /var/log/auth.log to monitor when administrative privileges are exercised.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Add a User to Sudoers in Ubuntu — Configure sudo policies and permissions for non-root users.
- How to Create a Sudo User on Ubuntu — Set up unprivileged user accounts with administrative capabilities.
- Initial Server Setup on Ubuntu 24.04 LTS — Foundational Linux server security hardening guide.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/var/log/auth.log of who executed administrative actions, and prevents accidental system-destroying typos.sudo -i prompts for the individual user's personal password and verifies membership in the sudoers file. su - prompts for the global root superuser password, which requires sharing a single credential across multiple administrators./etc/crontab and /etc/cron.d/ execute under the root user UID 0 directly via system scheduling without requiring password authentication.PermitRootLogin prohibit-password is set in /etc/ssh/sshd_config and an authorized public key resides in /root/.ssh/authorized_keys, cryptographic SSH key login remains functional while password logins are blocked.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!