Learn how to enable root user with SUDO
The root user in Linux grants unrestricted access to the system. While convenient, it can be a security risk. For this reason, many distributions disable root login by default. With our Cloud Servers, root is disabled by default.
There are situations where you might need to enable it. This guide will show you how to enable a disabled root user on Linux, assuming you have access to a user account with sudo privileges.
Important Note: Enabling root login is generally not recommended. It’s safer to use the sudo
command to elevate your privileges for specific tasks. Proceed with caution and only if absolutely necessary.
Steps
Log in with sudo: Use SSH or the local terminal to log in with a user account that has sudo privileges.
Become root (temporarily): Use the sudo -i
command to switch to the root user for the current session. Enter your sudo password when prompted.
Set a password for root: Since the root login is disabled, it likely won’t have a password set. Use the passwd
command to set a secure password for the root user:
sudo passwd root
You will be prompted to enter and confirm a new password for the root user.
(Optional) Enable remote root login (not recommended): By default, remote root login via SSH is disabled for security reasons. If you absolutely must enable it, edit the SSH configuration file
sudo nano /etc/ssh/sshd_config
Find the line that reads PermitRootLogin
and uncomment it (remove the #
symbol if present) and set the value to yes
. Save the file and exit the editor.
Reload SSH service (if applicable): If you made changes to SSH configuration in step 4, restart the SSH service for the changes to take effect:
sudo systemctl restart sshd
Remember: Enabling root login, especially remote root login, increases security risks. It’s generally recommended to use sudo
for administrative tasks instead. If you must enable root login, disable it again as soon as you’ve completed your task.