4 Ways to Access Root on Linux

Table of contents:

4 Ways to Access Root on Linux
4 Ways to Access Root on Linux

Video: 4 Ways to Access Root on Linux

Video: 4 Ways to Access Root on Linux
Video: Removing Recent Chats On Skype On A Samsung Tablet - Part 3 2024, November
Anonim

The root account on a Linux-based computer is an account with full permissions. You will need to use the root account to execute certain commands, especially those that affect system files. Since the root account can affect the computer as a whole, it's best to use this account only as needed, rather than using it in place of a regular account. In this way, you reduce the risk of "accidents" damaging important system files.

Step

Method 1 of 4: Accessing root from Terminal

Become Root in Linux Step 1
Become Root in Linux Step 1

Step 1. Open Terminal by pressing Ctrl+Alt+T

Most Linux distributions allow you to access the Terminal with this shortcut.

Become Root in Linux Step 2
Become Root in Linux Step 2

Step 2. Enter the command su - and press Enter

The computer will try to access the super user account. You can use this command to log into any account on the system, but if you don't specify an account name, you'll be logged into the root account.

Become Root in Linux Step 3
Become Root in Linux Step 3

Step 3. After typing the command su - and pressing Enter, enter the root password if prompted

If you receive an authentication error, your root account may be locked. Read the next steps to open an account

Become Root in Linux Step 4
Become Root in Linux Step 4

Step 4. Check the command line

When logged in as root, the command line will end in # instead of $.

Become Root in Linux Step 5
Become Root in Linux Step 5

Step 5. Enter the command that requires root access

After using the su - command to log in as root, you can use any command that requires root access. The su command is saved until the end of the session so you don't have to enter your root password every time you run the command.

Become Root in Linux Step 6
Become Root in Linux Step 6

Step 6. Consider using the sudo command instead of su -

The sudo (super user do) command allows you to run a command as root. sudo is highly recommended for most Linux users because by using sudo, root access is not saved, and the user does not need to know the root password. Users will only be asked to enter their respective passwords.

  • Enter the sudo command and press Enter (eg sudo ifconfig). After that, enter your account password when prompted.
  • The sudo command is the recommended command for root access on distributions that lock the root account, such as Ubuntu. Even if the root account is locked, you can still use sudo.
  • The sudo command can only be used by users with Administrator privileges. Access rights can be granted and revoked by editing the /etc/sudoers file.

Method 2 of 4: Unlocking Root Access (Ubuntu)

Become Root in Linux Step 7
Become Root in Linux Step 7

Step 1. Open root access in Ubuntu Linux

Ubuntu and various other Linux distributions lock the root account so that it cannot be accessed by normal users. This step is done because a root account is generally not required. Instead, the distribution allows root access via the sudo command (described in the previous step). Once the root account is unlocked, you can log in as root.

Become Root in Linux Step 8
Become Root in Linux Step 8

Step 2. Open Terminal by pressing Ctrl+Alt+T

Become Root in Linux Step 9
Become Root in Linux Step 9

Step 3. Enter sudo passwd root and press Enter

Enter your account password when prompted.

Become Root in Linux Step 10
Become Root in Linux Step 10

Step 4. Create a password for the root account, and re-enter it to confirm it

After setting the password, the root account will be active.

Become Root in Linux Step 11
Become Root in Linux Step 11

Step 5. Lock the root account with the following command:

sudo passwd -dl root

Method 3 of 4: Log in to System as root

Become Root in Linux Step 12
Become Root in Linux Step 12

Step 1. Consider using another way to access the root account

Accessing the root account directly for daily use is not recommended as you may run malicious commands. Only use the root account to perform emergency system repairs, such as recovering an unusable drive or restoring an inaccessible account.

  • Using the command sudo or su, instead of logging in as root, allows you to take advantage of the root account without experiencing the harm. Both commands will make you think twice before using any particular command.
  • Certain Linux distributions, such as Ubuntu, lock the root account until you manually unlock it. Apart from preventing users from tampering with the system with the root account, this step also protects the system from hackers because hackers will generally target the root account first when hacking the system. If the root account is locked, hackers cannot access the account. Read the previous steps to access root account in Ubuntu.
Become Root in Linux Step 13
Become Root in Linux Step 13

Step 2. Enter root as the username when prompted to log into the Linux system

If the root account is unlocked and you know the password of the account, you can log in as root directly.

If you need root access to run certain commands, use some of the steps above first

Become Root in Linux Step 14
Become Root in Linux Step 14

Step 3. After entering root as the username, enter the root password when prompted

  • On many systems, you can access root with the password "password".
  • If you forget or don't know your root password, read the next steps to find out how to reset your password.
  • If you are using Ubuntu, the root account is locked and cannot be used until you manually unlock it.
Become Root in Linux Step 15
Become Root in Linux Step 15

Step 4. Avoid running complex programs while using the root account

The program you are running may damage the system if accessed with the root account. Instead of using the root account, run commands that require administrator access with the sudo or su commands.

Method 4 of 4: Recovering Root or Administrator Password

Become Root in Linux Step 16
Become Root in Linux Step 16

Step 1. Reset root password if you can't remember it

If you don't remember your root password and user account, you may need to access recovery mode to change both passwords. If you know your user account password and want to change the root password, use the command sudo passwd root. After that, enter your account password and a new password for the root account.

Become Root in Linux Step 17
Become Root in Linux Step 17

Step 2. Restart your computer, then press Shift after the BIOS screen appears to open the GRUB menu

You may need to repeat this step several times before the GRUB menu appears

Become Root in Linux Step 18
Become Root in Linux Step 18

Step 3. Select the first (recovery mode) entry in the list that appears

Your Linux distribution's recovery menu will appear on the screen.

Become Root in Linux Step 19
Become Root in Linux Step 19

Step 4. Select the root option from the menu

A terminal with root privileges will load.

Become Root in Linux Step 20
Become Root in Linux Step 20

Step 5. Open a drive with read-write privileges

When you use Linux recovery mode, your drive is read only. Use the following command to enable write permissions:

mount -rw -o remount /

Become Root in Linux Step 21
Become Root in Linux Step 21

Step 6. After logging in as root and changing drive permissions, create a new password for the locked account

  • Enter the command passwdAccountName and press Enter. If you want to change the root password, enter passwd root.
  • Enter the new password twice when prompted.
Become Root in Linux Step 22
Become Root in Linux Step 22

Step 7. Restart the computer after resetting the password

After the computer restarts, you can use the computer as before with the password you set earlier.

Warning

  • Only use the root account if absolutely necessary. Log out of the account when you are done using it.
  • Give the root password only to users you trust and really need it.

Recommended: