3 Min Read · Ubuntu 26.04 LTS · sudo, su and passwd
The Root Account on Ubuntu
To enable the root account on Ubuntu 26.04, run sudo passwd root and set a password. To disable it again, run sudo passwd -l root. If you only need a root shell for a few commands, sudo -i gives you one without enabling root at all.
Below: how to check whether root is enabled, switch to it with su, lock it again, and why root still cannot sign in at the login screen or over SSH. If something here does not match your system, leave a comment or contact us.
The second field is what matters. L means locked, which is the default. P means root has a usable password. NP means it has no password at all.
2
Give root a password
Enable root by setting its password
sudo passwd root
mike@ubuntu:~$ sudo passwd root
New password:
Retype new password:
passwd: password updated successfully
sudo asks for your own password first. Then type the new root password twice. Nothing shows while you type. Use a different password from your own, and a strong one: it unlocks the whole system.
3
Switch to root
Log in as root
su -
mike@ubuntu:~$ su -
Password:
root@ubuntu:~#
Enter the root password. The prompt ends in # while you are root. Type exit to go back to your own account.
Disable the Root Account Again
Lock the root account
sudo passwd -l root
Check it worked with sudo passwd -S root. The second field should read L again. Locking root does not affect sudo, so your own account keeps its admin rights.
Note
Locking the password does not block SSH keys. If you ever added a key for root, remove the file /root/.ssh/authorized_keys too, or root can still log in with that key.
Get a Root Shell Without Enabling Root
For most jobs you never need to enable root. These all use your own password:
Command
What it does
sudo command
Runs one command as root
sudo -i
Opens a root shell, starting in root’s home folder
sudo -s
Opens a root shell and stays in the current folder
exit
Leaves the root shell
Open a root shell
sudo -i
mike@ubuntu:~$ sudo -i
root@ubuntu:~# whoami
root
Ubuntu 26.04 uses sudo-rs, a rewrite of sudo, for its sudo command. These options work the same way. More examples are in our sudo command cheat sheet.
Root Login on the Desktop and Over SSH
Giving root a password does not let it sign in everywhere. Ubuntu blocks two routes on purpose.
Desktop
Root cannot sign in at the login screen
The login screen refuses root, even with a password set. Sign in as yourself and use sudo instead. We do not recommend changing this: every app you open would run with full control of the system.
SSH
Root can only log in with a key
Ubuntu’s SSH server is set to PermitRootLogin prohibit-password, so a root password never works over SSH. Root can only log in with an SSH key. To see the setting on a machine running the SSH server:
Show the root login setting
sudo sshd -T | grep -i permitrootlogin
without-password is another name for the same setting.
If Something Goes Wrong
Fix
su says Authentication failure
Root is still locked, or the password is wrong. Check with sudo passwd -S root. If it shows L, set a password as in step 2, or use sudo -i instead.
Fix
sudo says you are not in the sudoers file
Your account is not an administrator. Sign in as a user who is, add your account to the sudo group, then log out and back in:
Give a user admin rights
sudo usermod -aG sudo mike
Use your username in place of mike.
Fix
You forgot your own password and root is locked
For a fuller walkthrough, see how to reset an Ubuntu root or administrator password. Restart and hold Shift, or press Esc on a UEFI machine, to open the boot menu. Choose Advanced options for Ubuntu, then a (recovery mode) entry, then root. At the root prompt:
sudo-rs ↗The sudo that ships with Ubuntu 26.04, and how it differs
r/Ubuntu ↗Ask about sudo and root and see what worked for others
Frequently Asked Questions
Is the root account enabled on Ubuntu?
No. Ubuntu installs with the root account locked. Your own account does admin work with sudo, using your own password.
What is the default root password on Ubuntu?
There is none. Root has no usable password until you set one with sudo passwd root.
How do I switch to root on Ubuntu?
Run sudo -i and enter your own password. That works with root locked. If you have given root a password, su – also works, using the root password.
How do I disable the root account on Ubuntu?
Run sudo passwd -l root. Check it with sudo passwd -S root: the second field should read L.
What is the difference between sudo -i and su?
sudo -i asks for your own password and works with root locked. su – asks for the root password, so root must have one.
Is it safe to enable the root account?
It works, but it adds a second password that controls the whole system. Most people never need it. If you enable it for a task, lock it again when you are done.
Root locked again?
Keep Ubuntu secure
The commands for checking users, logins, open ports and updates on an Ubuntu system.