How to become a Linux superuser

Table of contents:

How to become a Linux superuser
How to become a Linux superuser
Anonim

The Linux superuser account grants full access to the system. Superuser (administrator) rights are required to execute commands in Linux, especially those commands that affect system files. Since the superuser account has unrestricted access to system files, it is recommended that you obtain superuser rights only when necessary, and not log in as an administrator. This will help prevent accidental damage to important system files.

Steps

Method 1 of 4: Obtaining superuser rights from the terminal

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

Step 1. Open a terminal

To do this, in many distributions, you need to press Ctrl + Alt + T.

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

Step 2. Enter

su - and press ↵ Enter. With this command, you can log in as superuser. Use the specified command to log in as any user, but if the command does not contain a username, you will be logged in as an administrator.

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

Step 3. Enter the superuser password (when prompted)

After entering the su - command and pressing ↵ Enter, the system will ask you to enter the administrator password.

If you get an authentication error message, it is most likely that the superuser account has been locked out. To find out how to unblock your account, read the next section

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

Step 4. Pay attention to the command prompt (in the terminal window)

If you are granted superuser privileges, a # icon appears at the end of the command prompt instead of the $ icon.

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

Step 5. Enter the commands that you need superuser rights to execute

After logging in with the su - command and gaining superuser privileges, you can run any commands that require administrative access. The activity of the su command is saved until the end of the session, so the superuser password does not need to be entered every time you need to execute the next command.

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

Step 6. Instead of the su command, you can use the command

sudo. The sudo command allows you to run other commands when superuser privileges are granted for a limited time. Most users are advised to use this command to run commands that require administrative access, because in this case the user is not logged on as superuser and it is not necessary to know the administrator password. Instead, the user enters his user password to gain superuser rights for a limited time.

  • Type sudo command and press ↵ Enter (e.g. sudo ifconfig). Enter your user password, not the superuser password.
  • The sudo command is recommended for use on some Linux distributions, such as Ubuntu, because it works even when the superuser account is locked out.
  • This command is available to users with administrator rights. You can add or remove a user in / etc / sudoers.

Method 2 of 4: Unlocking the Superuser Account (Ubuntu)

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

Step 1. Unlock the superuser account (Ubuntu)

In Ubuntu (and several other distributions), the superuser account is locked out, so a regular user cannot access that account. This is because you do not need superuser access to use the sudo command (see previous section). By unlocking the superuser account, you can log on as an administrator.

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

Step 2. Open a terminal

If you are running a distribution with a graphical user interface, press Ctrl + Alt + T to open a terminal.

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

Step 3. Enter

sudo passwd root and press ↵ Enter. Enter your user password.

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

Step 4. Create a new password

The system will offer to create a new password; enter it twice. After creating a password, the superuser account will be unlocked.

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

Step 5. Block the superuser account again

If you need to block the superuser account, enter the following command to remove the password and block the account:

sudo passwd -dl root

Method 3 of 4: Logging in as superuser

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

Step 1. Use other methods to gain temporary administrative access

It is not recommended to log in regularly as superuser because you can accidentally execute commands that will crash the system. Log on as an administrator for troubleshooting purposes only, such as fixing failed drives or recovering locked accounts.

  • Instead of logging in as an administrator, use the sudo or su commands to prevent accidental damage to important system files. These commands allow you to think about the consequences before irreparable damage is done to the system.
  • In some distributions, for example, in Ubuntu, the administrative account is locked by default (you need to unlock it manually). This approach protects the system not only from accidental or rash user actions, but also from potential hacker attacks, which are primarily aimed at the superuser account. If the administrative account is locked, an attacker will not be able to access it. Read the previous section to find out how to unlock the superuser account in Ubuntu.
Become Root in Linux Step 13
Become Root in Linux Step 13

Step 2. In the Linux login window, enter

root. If the superuser account is not locked out and you know the administrative password, you can log on as superuser. In the login window, enter root as the username.

If superuser rights are required to execute the command, use the method described in the previous section

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

Step 3. Enter the superuser password

After entering root (as the username), enter the administrator password.

  • In some cases, the word password is used as a password.
  • If you do not know or have forgotten your superuser password, read the next section to learn how to reset your password.
  • In Ubuntu, the superuser account is locked by default and cannot be used until unlocked.
Become Root in Linux Step 15
Become Root in Linux Step 15

Step 4. Once logged into the superuser account, do not run complex programs

There is a possibility that such a program, run with superuser rights, will have a negative impact on the system. Therefore, it is recommended that you use sudo or su to run programs rather than logging in as superuser.

Method 4 of 4: Resetting the superuser password

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

Step 1. If you forgot your superuser password and your user password, please reset them

To do this, boot the system into recovery mode. If you know your user password but need to change the superuser password, enter sudo passwd root, then enter the user password, and then create a new administrative password.

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

Step 2. Restart your computer and after the BIOS screen appears, hold down the left key

⇧ Shift. The GRUB menu will open.

Holding the key in time is quite difficult, so you may have to make several tries

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

Step 3. Select the first option from the list

(recovery mode) The installed distribution will be loaded in recovery mode.

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

Step 4. In the menu that opens, select an option

root. A terminal with superuser rights will open.

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

Step 5. Mount the disk to activate write permission

In recovery mode, the drive usually only has read permission. Enter the following command to enable writing:

mount -rw -o remount /

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

Step 6. Create a new password for any account that you do not have access to

After logging in as an administrator and changing access rights, you can create a new password for any account.

  • Enter passwd account and press ↵ Enter. To change the superuser password, enter passwd root.
  • Enter your new password twice when prompted.
Become Root in Linux Step 22
Become Root in Linux Step 22

Step 7. After resetting passwords, restart your computer

The system will boot normally. The new passwords will take effect immediately.

Warnings

  • Log into the superuser account only when necessary, and remember to log out of this account.
  • Only give the superuser password to people you trust and need to know the password.

Popular by topic