Skip to content
Follow
Ubuntu Linux

How to Enable Root User on Ubuntu 24.04

Richard
Written by
Richard
Feb 27, 2025 Updated Oct 11, 2026 5 min read
How to Enable Root User on Ubuntu 24.04
How to Enable Root User on Ubuntu 24.04

The root user on Ubuntu 24.04 is the built-in administrator account. It has complete control over every file, service and setting on the system. Ubuntu keeps this account locked by default, so nobody can log in as root until you give it a password. That protects the computer from accidental mistakes, because a single wrong command run as root can delete or break system files with no confirmation.

Advertisement

Enabling direct root access takes a few steps in the terminal. You use sudo to set a password for root, and after that you can switch to the root user whenever you need to manage system files. This guide also covers how to restrict the su command, so that only trusted users can reach the root account. You need an account that can use sudo, which is the first user created during installation.

⚡ Quick Answer

Set a password for the root account using `sudo passwd root`. Then, switch to the root user with `su -`. This grants full administrative privileges to your Ubuntu system.

Advertisement

Enable root

To enable the root user on Ubuntu 24.04, you open a terminal and set a password for the built-in administrator account. Setting that password is what unlocks the account. After that you can log in as root directly whenever you need to do advanced administrative work.

The first step is to get an administrator shell with the sudo -i command. Then you set a strong password for root. Pick something long and unique, because anyone who knows it gets full control of the machine.

  1. Press Ctrl+Alt+T to open a terminal, or search for Terminal in the Activities overview.
  2. Run the sudo command shown below.
🐧Bash / Shell
sudo -s

The terminal asks for your current password. This is the password of your own user account, not the root password, which does not exist yet. Type it and press Enter. Nothing appears on screen while you type, not even dots. That is normal, so keep typing and press Enter when you are done.

Next, run the command that sets the root user’s password. It works from your sudo session, so it does not ask for a root password first.

Advertisement
🐧Bash / Shell
sudo passwd root
  1. Type the new password for the root account when the terminal asks for it, then press Enter.
  2. Type the same password again to confirm it, then press Enter.

Again, nothing is shown while you type. If the two entries do not match, the terminal tells you the passwords do not match and you have to run the command again. When it works, you see a message that the password was updated successfully.

💻Code
New password: 
Retype new password:
passwd: password updated successfully

Setting the root password enables the account automatically. No restart or logout is needed. To undo this later, lock the root account again with the lock option of the passwd command (see its man page). Ubuntu then goes back to its default state.

Now switch your active shell to the root user.

  1. Run the command shown below.
  2. Enter the root password you just created when the terminal asks for it.

The prompt changes after a successful switch. It begins with "root" and ends with "#" instead of the usual "$". That is your confirmation that every command now runs with the highest level of system privileges, with complete control over the whole Ubuntu 24.04 system. Be careful what you type here. When you finish, close the root shell by typing exit and pressing Enter, which returns you to your normal user.

Advertisement
💻Code
root@Ubuntu:~# 

Restrict the su command

Once root has a password, any local user who learns or guesses it can use the su command to become root. To reduce that risk, you restrict su by editing the Pluggable Authentication Modules (PAM) configuration file for switching users. The change forces users to belong to a specific security group before they can run su. Everyone else is refused, even if they know the password. The edit is a small change to one text file in the terminal.

Run the command below to open the su configuration file. You need sudo rights for this, because the file is owned by root.

💻Code
nano /etc/pam.d/su
  1. Find the line highlighted in the screenshot below.
  2. Remove the # at the start of that line to uncomment it.

The line should now start with the module name and no hash symbol. Leave the rest of the file as it is.

💻Code
# Uncomment this to force users to be a member of group adm
# before they can use `su'.
auth required pam_wheel.so group=adm

Save your changes and exit the editor. If the file opened in nano, press Ctrl+O, then Enter to write the file, and Ctrl+X to close it. The change takes effect immediately, with no restart.

Advertisement

With the restriction active, only members of the adm group can use the su command. To allow a user to switch to the root account, add that user to the adm group with the command below. The user has to log out and back in before the new membership applies. Add only people you trust, because membership in this group lets them attempt to become root.

💻Code
usermod -aG adm richard

The configuration is finished. Root has a password, and only members of the adm group can use su to reach it.

Summary:

Root access gives total control over every file and service on the machine. Treat the account with care, and use it only when a task really needs it, to keep the operating system stable.

  • The root account offers full administrative access and can perform any task on the system.
  • By default, the root account is locked to enhance security.
  • You can enable the root account with the sudo command, which sets a password for it.
  • Limiting the use of the su command helps prevent unauthorized access to the root account.
  • Only add trusted users to the adm group to maintain system integrity.
  • Review user permissions and access to the root account regularly to ensure ongoing security.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

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