How to Become a Root User in Linux (with Pictures)

Table of contents:

How to Become a Root User in Linux (with Pictures)
How to Become a Root User in Linux (with Pictures)
Anonim

The "root" account of a Linux system is the user profile that has full control of the computer. Logging into your computer as "root" is required to be able to execute Linux operating system specific commands, especially when it comes to procedures related to modifying the system's configuration or files. Since the "root" account has total control of the computer and the data it contains, it is best to use it only when absolutely necessary and avoid logging on to the computer directly with that user profile. This way the chances of accidentally deleting or modifying critical system files will be very low.

Steps

Part 1 of 4: Getting Root Access from a Terminal Window

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

Step 1. Open a "Terminal" window

If you haven't already opened one, do it now. Many Linux distributions allow you to quickly access the "Terminal" app by simply pressing the key combination Ctrl + Alt + T.

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

Step 2. Type the command

on - and press the button Enter.

This way you will be able to log in as a "super user". In reality, this command allows you to log in to the system (limited to the "Terminal" window) with any of the user accounts present. However, when used with the given syntax it allows you to gain the privileges of the "root" account.

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

Step 3. When prompted, enter the "root" user login password

After typing the command su - and pressing the Enter key you will be asked to type the login password.

If the "authentication error" message appears, it most likely means that the "root" account is currently disabled. In this case, read the next section of the article to find out how to enable its use

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

Step 4. Check the symbol that identifies the command prompt

After successfully logging in as "root", the command prompt should end with the # symbol instead of the classic $.

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

Step 5. Type a command that requires the "root" account access privileges to execute

After running the su - command, you will be able to execute any command within the "Terminal" window to gain access privileges for the "root" user. The effects of the su command will remain in effect until you close the "Terminal" window, so you don't need to provide the authentication password to run each command.

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

Step 6. Consider using the command

I sweat instead of the command on -.

The sudo command (from English "super user do") allows you to execute individual commands with the access privileges of the "root" user. This is the best way to run Linux special commands that require system administrator access, but with the advantage that these privileges are limited only to the command being executed; furthermore, the user who executes them does not need to know the access password of the "root" account. In this case it is sufficient to provide your login password to be able to execute the command.

  • Type the command sudo command_syntax and press the Enter key (for example sudo ifconfig). When prompted, provide the authentication password for your user account and not the "root" user password.
  • Using the sudo command is the preferred method for executing special commands on Linux distributions such as Ubuntu, as it ensures that your goals are achieved even when the "root" account is locked out.
  • The use of the "sudo" command is limited to users who are also system administrators. User accounts that must use it or that must not use it can be added or removed from the / etc / sudoers file.

Part 2 of 4: Enable Root User Usage (Ubuntu)

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

Step 1. Unblock the use of the "root" user

Ubuntu (and several other Linux distributions), by default and for security reasons, does not allow the use of the "root" account. This choice is justified by the fact that access to the system with the "root" account is necessary only on rare occasions, while in most cases it is sufficient to use the sudo command (described in the previous method of the article). Unblocking the use of the "root" user account allows you to log in to the computer using that profile.

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

Step 2. Open a "Terminal" window

If you are using a Linux distribution with a graphical interface, you can press the hotkey combination Ctrl + Alt + T.

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

Step 3. Type the command

sudo passwd root and press the button Enter.

When prompted, enter your user account login password.

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

Step 4. Set a new password for the "root" user

At this point you will be asked to create a new security password and type it twice to verify its correctness. After performing this step, you will be able to use the "root" account to log into the Linux environment.

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

Step 5. Disable the use of the "root" profile again

If you need or want to disable the "root" account again, run the following command which will delete the profile login password:

sudo passwd -dl root

Part 3 of 4: Login with the Root Account

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

Step 1. Consider using one of the other methods described in this article to get "root" user access permissions

Remember that logging into your computer directly with the "root" account on a regular basis is not recommended, as it would be very easy to mistakenly execute a command that could render the entire system unusable. Furthermore, a scenario would arise that would jeopardize the security of the data on the computer, especially if you use the SSH network protocol to be able to access it remotely. Direct access to the system as a "root" user should only be performed in emergency cases, when it is necessary to perform maintenance or an extraordinary repair of the system, for example in the event of a hard disk malfunction or to restore normal use of a locked account.

  • Instead of logging into your computer as the "root" user, consider using the sudo or su commands. This will reduce the chances of being able to harm your entire system by acting in error. Using the commands indicated, the user will have the possibility to think carefully about the action he wants to take, minimizing the possibility of making serious mistakes.
  • Some Linux distributions, for example Ubuntu, by default disable the use of the "root" user account which can only be used after having configured it manually. In this way not only inexperienced and unaware users will not be able to cause any serious damage to the system using the privileges given by the "root" account, but the whole computer will be safe from possible attacks perpetrated by hackers, since normally their target is just to log into your computer via the "root" account. When the use of the "root" user profile is disabled, hackers or attackers cannot in any way gain access to the system with that account. If you need to unblock the use of the "root" user on an Ubuntu system, please refer to the previous method of the article.
Become Root in Linux Step 13
Become Root in Linux Step 13

Step 2. Type the string

root inside the username text field to log in to the Linux system.

If the "root" account is active and you know its security password, you can use it to log into your computer. Type the root username in the appropriate text field as soon as the login screen appears.

If you need to log into your computer as "root" to be able to execute a command, use one of the methods described earlier in the article

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

Step 3. Enter the login password of the "root" user account

After typing root as the username with which to log in to Linux, when prompted, also provide its security password.

  • In many cases the login password of the "root" user might be "password".
  • If you do not know the login password of the "root" account or you have simply forgotten it, continue reading the next method of the article to reset it.
  • In Ubuntu the "root" account is locked out by default and cannot be used until it is activated manually.
Become Root in Linux Step 15
Become Root in Linux Step 15

Step 4. While logged into the system with the "root" user account, avoid using complex programs or commands

In this scenario there is a possibility that the program you want to use may have a negative impact on the system by having the access privileges of the "root" account. As mentioned above, it is preferable (and highly recommended) to use the sudo or su commands to execute specific programs or commands, rather than log in directly to the computer as the "root" user.

Part 4 of 4: Reset the Root Account Password

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

Step 1. Reset the security password of the "root" account, if you have forgotten it

If you have forgotten both the password of the "root" account and that of your personal account, to be able to reset them you will have to start the computer in "recovery" or "recovery" mode. If, on the other hand, you know the login password of your user profile, you can change that of the "root" account by simply using the command sudo passwd root and then provide your login password and create a new one for the "root" account.

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

Step 2. Restart your computer while holding down the key

⇧ Shift left after the BIOS screen appears.

This will display the "GRUB" menu.

Pressing the indicated key with the correct timing can be a bit complex, so if you get it wrong, you will simply have to try again several times

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

Step 3. Select the first option

(recovery mode) menu appeared.

This will cause your Linux distribution to boot into "recovery" mode.

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

Step 4. Now choose the item

root from the new list of options that appeared.

The "Terminal" window will start, where you can log in as the "root" user.

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

Step 5. Enable write permissions on the file system

When booting in "recovery" mode, the computer's file system is normally protected, ie the user has only read and not write access to the data. To also enable write access, run the following command:

mount -rw -o remount /

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

Step 6. Now create a new security password for all user accounts you want to change

After you have acquired the privileges of the "root" user within the "Terminal" window and have changed the access permissions to the file system, you will be able to set a new password for each account on the system:

  • Type the command passwd account_name and press the Enter key. For example, if you need to change the password of the "root" account, you will need to execute the command passwd root.
  • When prompted, type your new password twice.
Become Root in Linux Step 22
Become Root in Linux Step 22

Step 7. After resetting all passwords, restart your computer to be able to use it as usual

The new passwords will be active with immediate effect.

Warnings

  • Use the "root" account only on occasions when it is really needed, then log out immediately to return to using a normal user account.
  • Share the password of the "root" account only with people you trust and who really need to know this information.

Recommended: