How to Root on Ubuntu: 10 Steps (with Pictures)

Table of contents:

How to Root on Ubuntu: 10 Steps (with Pictures)
How to Root on Ubuntu: 10 Steps (with Pictures)

Video: How to Root on Ubuntu: 10 Steps (with Pictures)

Video: How to Root on Ubuntu: 10 Steps (with Pictures)
Video: How to check IP address of server or machine in linux? | Easiest way 2024, November
Anonim

You need root access (also known as superuser) to run administrative programs on Linux. Generally, Linux distributions provide a separate root account, but that account is locked on Ubuntu Linux by default for security. To run a command with root access, use sudo.

Step

Method 1 of 2: Running Root Commands with Sudo

Become Root in Ubuntu Step 1
Become Root in Ubuntu Step 1

Step 1. Press Ctrl+Alt+T to open a Terminal window

Unlike other Linux distributions, Ubuntu locks the root account by default. Therefore, you cannot use the su command to run a root terminal. To replace su, use sudo.

Become Root in Ubuntu Step 2
Become Root in Ubuntu Step 2

Step 2. Enter sudo at the beginning of the command

sudo, short for super user do, lets you run commands on Linux as root.

  • For example, the command sudo /etc/init.d/networking stop will stop network services, and sudo adduser will add a new user to the system. The two commands above actually have to be run as root.
  • You will be prompted for the account password before sudo runs the command. Linux stores your password for 15 minutes so you don't have to type it every time you run a command.
Become Root in Ubuntu Step 3
Become Root in Ubuntu Step 3

Step 3. Use the gksudo command to run programs with a graphical interface that require root access

For security reasons, Ubuntu does not recommend that you use sudo to run programs with a graphical interface. Instead, start a command to open a graphical interface program with gksudo.

  • For example, use the command gksudo gedit /etc/fstab to open the fstab file in GEdit, a text-editing program with a graphical interface.
  • If you are using KDE, replace gksudo with kdesudo.
Become Root in Ubuntu Step 4
Become Root in Ubuntu Step 4

Step 4. Simulate root access with the command sudo –i if you need root shell access to run certain scripts

The command lets you access the superuser account and environment variables.

  • Enter the command sudo passwd root to create a password and activate the root account. Remember the password.
  • Enter sudo -i, then provide the root password when prompted.
  • The command line will change from $ to #. The # symbol indicates that you have root access.
Become Root in Ubuntu Step 5
Become Root in Ubuntu Step 5

Step 5. Give sudo access to users who don't have access yet by adding them to the sudo group

Use the command usermod -aG sudo username, and replace "username" with the name of the user you want to grant access to.

Method 2 of 2: Enabling Root Account

Become Root in Ubuntu Step 6
Become Root in Ubuntu Step 6

Step 1. Press Ctrl+Alt+T to open a Terminal window

Unlike other Linux distributions, Ubuntu locks the root account by default for security. To safely run commands with root privileges, use

sudo

or

gksudo

. If you really need to access the root account, for example for an important program that only one user has access to, you can enable the root account with a simple command.

Enabling the root account may harm the system. Ubuntu does not recommend that you enable the root account

Become Root in Ubuntu Step 7
Become Root in Ubuntu Step 7

Step 2. Enter the command sudo passwd root and press Enter

You will be asked to enter a new password for the root account. Don't forget this password.

Become Root in Ubuntu Step 8
Become Root in Ubuntu Step 8

Step 3. Enter the password, then press Enter

Become Root in Ubuntu Step 9
Become Root in Ubuntu Step 9

Step 4. Repeat the password when prompted, then press Enter

Now, the root account is password protected and accessible.

Become Root in Ubuntu Step 10
Become Root in Ubuntu Step 10

Step 5. Enter su - and press Enter

Enter the root password when prompted to access the account.

To disable the root account, use the command sudo passwd -dl root

Tips

  • Wherever possible, avoid using the root account directly. You can run almost any command with root privileges via sudo or gksudo.
  • You can also use the command sudo –i to access other user accounts on the system. For example, to access the user "ayu", use the command sudo –I ayu and enter your password (instead of Ayu's).

Recommended: