Linux users will inevitably need to log into the root account, or use administrator privileges, quite frequently. Tasks like installing or removing software, configuring system settings, adjusting file permissions, and many others usually require access to the root user account in order to perform. The root account can be accessed either by logging directly into the account, or by using the sudo
Linux command to temporarily access root and execute a command with administrator privileges. In this tutorial, we will show you how to change to the root account on a Linux system, and how to use sudo
to execute commands with root privileges.
In this tutorial you will learn:
- How to log in to the root account
- How to use the
sudo
command - How to open a new terminal as the root user

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | N/A |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
How to Switch to Root User on Linux
Here are a few different methods to switch to the root user on Linux. Depending on your Linux distribution and the way your user is configured (i.e., whether they have
sudo
access or not), you may find that one method works better than another, so try them all.
- The majority of Linux distributions come with the
sudo
convention configured by default for the user that is set up during installation. If your user has access to thesudo
command, then you can switch to the root account by appending the-i
option, like so:$ sudo -i
Logging into the root user account by using the sudo command in Linux After providing your sudo password, you will be logged into the root account and no longer required to continue prefacing your commands with
sudo
in order to run them with root privileges. - Alternatively, there is no reason to log into the root user account if you have access to the
sudo
command and simply want to run a few commands as the root user. This is actually the recommended approach, as it is more secure than having users to log into the root account directly. For example, to run a command as root, preface it withsudo
:
$ sudo whoami root
Although we are running this command as an ordinary user, the whoami command shows us the effective user that is running the command, which is root.
DID YOU KNOW?
See our tutorial on giving a user sudo permissions if your account has not yet been configured to use thesudo
command. - If your user does not have
sudo
permissions, you should be able to log in to the root user account via thesu
command. In this case, you will need to know the password of the root user. The majority of times, you will want to append the-
option, in order to update your local environment variables.$ su -
WARNING
The above command will only work if the root account has a password configured. On some systems, the root account does not have a password by default, and instead is expected to be accessed strictly viasudo
as shown in the above methods.If your root account does not have a password and you need to set one, you can execute the following command. Note that this is going against security recommendations.
$ sudo passwd
After setting the root password, you will be able to log in with the
su
command. - Another option is to open a new terminal as the root user. The command for this will vary depending on your installed desktop environment, but if you want to open a brand new terminal as the root user on the GNOME desktop environment, you can execute the following command.
$ sudo gnome-terminal
This same method can also be used to launch other GUI applications as the root account, although many of them will not like being accessed by root, and may produce an error.
Closing Thoughts
In this tutorial, we saw how to switch to the root user account on a Linux system. The recommended approach is to use the
sudo
command in order to execute commands with root privileges, but we can also log directly into the root user account, either with the sudo -i
or su -
commands, depending on how our system and user account has been configured.