Linux users generally execute the command with sudo whenever the changes are going to affect the root system.
But what if you want to switch to the root user so that you don't have to use sudo with every command?
Unlike other Linux distributions, Ubuntu normally won't let you configure the root account while the installation process.
But you can switch to the root user with sudo:
Switch to root user in Ubuntu
In this tutorial, I'm going to share two ways by which you can switch to a root user in Ubuntu or any other Linux distribution:
- Using the sudo command
- Configuring the root account
So let's start with the first one.
1. Switch to root user using sudo
If you haven't configured the root account and don't want to, then refer to this method.
To switch to the root user, you have to execute the
su (switch user) and when executed without any options, it will switch to the root user:
When it asks for the password, you have to use your account password as you normally do with any other sudo command.
Also, the password entering is not shown on the terminal. Just type and press enter.
As you can see, when I used the whoami command, it showed I'm logged in as a root user.
2. Configure the root account and switch to it
As I said earlier, Ubuntu does not include any option to configure a root account while the installation process so if you want to configure the root account, then, here's how you do it.
To configure the root account, all you have to do is set the root password use the following command:
sudo passwd root
Once done, you can use the
su command without any options and enter the new password to switch to the root account:
And there you have it!
Forgot the sudo and root password? Let me help
If you forgot the sudo and root passwords then how would you recover the password? Well, it is quite easy and we made a dedicated tutorial for that:
Still, having issues to switch to the root account? Leave a comment and I'll help you out.