Introduction: On Ubuntu Linux root is a particular user account. By default, the root user has access to all commands, files, services on an Ubuntu Linux operating system. It is also known as the root account, root user and the superuser. The superuser or root user has root privileges. It is the most privileged account on Ubuntu with complete access to everything. The MS-Windows equivalent of root is the Administrators group or Administrator user. This page shows how to log in as root or superuser on Ubuntu to perform sysadmin related tasks.
How to become superuser on Ubuntu Linux
- Open a terminal Window. Press Ctrl+Alt+T to open the terminal on Ubuntu
- To become root user type:
- When promoted provide your password
- After successful login, the $ prompt would change to # to indicate that you logged in as root user on Ubuntu
Let us see all commands and examples in details.
How do I login as root on Ubuntu?
Open the Terminal application. Use the whoami command to verify user identity:
To login as root on Ubuntu, type the following sudo command:
$ sudo -i
Next type your password and your shell promot should change from $ to #:
To exit from sudo session of root user, type any one of the following exit command or logout command:
The -i option tells sudo to run the shell specified by the root user’s password database entry as a login shell. If you pass the -s to the sudo command, it runs the shell specified by the SHELL environment variable if it exists or the shell defined by the invoking user’s password database entry.
How to become root in Ubuntu Linux using su
By default, the root account password is locked in Ubuntu Linux for security reasons. This means that you cannot login as root directly or use the su command to become the root user. You must set up root password by running the following command in advance on Ubuntu based system:
sudo passwd root
See “How to change root password in Ubuntu Linux” for more info.
Type the following su command:
$ su -
You must know and type root user’s password when prompted:
su vs sudo to become superuser in Ubuntu Linux
|su command||sudo command|
|You must know the root user’s password.||No need to know the root user’s password.|
|The su command does not log usage or all arguments.||The sudo command logs sudo usage and all arguments.|
|If the root user password not set or root user is disabled, you can not use su command.||sudo works with or without a root user password. It uses your password and /etc/sudoers file to authenticate your session.|
This tutorial explains how to gain root access in the Ubuntu Linux terminal session using the sudo and su command. I recommend that you always use the sudo command to become root user on Ubuntu. For more info see this page here.