How do I become superuser on Ubuntu Linux using su/sudo?

last updated in Categories , ,

I replaced Windows 10 with Ubuntu Linux 16.04 LTS. So, I am a new Ubuntu Linux user. How do I become superuser on Ubuntu Linux? How do I login as root on Ubuntu?

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

  1. Open a terminal Window. Press Ctrl+Alt+T to open the terminal on Ubuntu
  2. To become root user type:
    sudo -i
    OR
    sudo -s
  3. When promoted provide your password
  4. 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:
$ whoami
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:
# logout
OR
# exit

How to become superuser on Ubuntu Linux using sudo command
How to become superuser on Ubuntu Linux using sudo 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:

How do I login as root on Ubuntu Linux using 'su -' command?
Login as root on Ubuntu Linux using ‘su -‘ command

su vs sudo to become superuser in Ubuntu Linux

su commandsudo 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.

Conclusion

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.

This entry is 3 of 6 in the root user Tutorial series. Keep reading the rest of the series:
  1. Linux Login as Superuser ( root user )
  2. How can I log in as root?
  3. How do I become superuser on Ubuntu Linux using su/sudo?
  4. Ubuntu Linux root Password (Default Password)
  5. How to change root password in Ubuntu Linux
  6. How to create a new sudo user on Ubuntu Linux server

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

1 comment

    Have a question? Post it on our forum!