Ubuntu, as a security-focused Linux distribution, comes with the root account disabled by default. Instead, users are encouraged to use the sudo
command to perform administrative tasks. However, there are situations where enabling the root user for direct access is necessary or more convenient, especially for advanced users. This guide explains how to enable the root user on Ubuntu 22.04 and provides important considerations for using it securely.
The root user in Linux is the superuser with unrestricted privileges over the entire system. It can perform any system-wide task, including installing software, managing users, and altering system configurations. However, because of its power, mistakes made while logged in as root can have catastrophic consequences.
For this reason, Ubuntu disables the root account by default, opting for a more secure approach using sudo
, which allows users to run commands with elevated privileges for a single task. This reduces the risk of accidental system damage and limits the potential impact of a security breach.
sudo
.sudo
commands are.The first step in enabling the root account is accessing the terminal, where you can run commands.
Ctrl + Alt + T
to open the terminal.Ubuntu does not set a password for the root account by default. You will need to assign one to activate it.
Run the following command to set the root password:
sudo passwd root
You will be prompted to enter a new password for the root user. Make sure to choose a strong password and confirm it by entering it again.
Once you’ve set a password, you can switch to the root user with the following command:
su -
After entering the password you set, you will have full root access, indicated by the #
prompt in the terminal.
If you plan to access your server remotely using SSH and want to log in directly as root, you will need to modify the SSH configuration. By default, Ubuntu disables root login via SSH.
To enable SSH root login, follow these steps:
sudo nano /etc/ssh/sshd_config
PermitRootLogin prohibit-password
Change it to:
PermitRootLogin yes
CTRL + X
, then Y
and Enter
.sudo systemctl restart ssh
You can now log in as root via SSH, but keep in mind that this introduces significant security risks. Use SSH keys for authentication if possible, rather than relying on passwords.
If you decide you no longer want the root account active, you can easily disable it by locking the root password:
sudo passwd -l root
This command locks the root account, preventing login. If you also want to disable SSH root access, edit the sshd_config
file again and change PermitRootLogin
back to no
:
PermitRootLogin no
Then restart the SSH service:
sudo systemctl restart ssh
Enabling the root account can be useful for system administration tasks, but it comes with risks. Here are a few tips to enhance security when using the root account:
exit
.While enabling the root account in Ubuntu 22.04 provides powerful administrative control, it should be done with caution. The default use of sudo
is usually sufficient for most tasks, but in some cases, direct root access may be more efficient. By following this guide, you can enable and use the root account safely while understanding the associated risks.