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

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.

ADVERTISEMENTS

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

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.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • Matt Dec 2, 2016 @ 21:26

    ALL should work:
    sudo -s
    OR
    sudo -i
    OR
    sudo su

    Cheers

    Matt.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.