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

Step 1. Open a terminal
To do this, in many distributions, you need to press Ctrl + Alt + T.

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.

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

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.

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.

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)

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.

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

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

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.

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

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.

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

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.

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

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.

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

Step 3. Select the first option from the list
(recovery mode) The installed distribution will be loaded in recovery mode.

Step 4. In the menu that opens, select an option
root. A terminal with superuser rights will open.

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 /

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.

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.