How to Get Root User Access in Ubuntu

Table of contents:

How to Get Root User Access in Ubuntu
How to Get Root User Access in Ubuntu
Anonim

To perform tasks that require administrative rights on a Linux system, you must use the "root" user (also known as "superuser"). For security reasons, many Linux distributions keep the user account separate from the administrative one, but in addition to this, on systems running Ubuntu, the use of the root user is disabled by default. This prevents an inexperienced user from performing operations that are harmful to the operating system or to the security of the data it contains. To execute a command that requires the use of the root user, use the sudo command.

Steps

Method 1 of 2: Perform Administrative Tasks Using the Sudo Command

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

Step 1. To access a "Terminal" window (the system shell), press the key combination Ctrl + Alt + T

Since Ubuntu prevents the use of the root account by default, it is not possible to use the su command to gain administrative rights for the root user as is the case in many other Linux distributions. In this case, you will need to use the sudo command.

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

Step 2. Use the sudo prefix for each command you need to execute

The acronym "Sudo" derives from the English "Super User Do". Using the "sudo" prefix, the command in question will be executed as root user, ie as system administrator.

  • For example, the sudo /etc/init.d/networking stop command stops the network service, while the sudo adduser command adds a new user to the system. Running both of these commands requires root access.
  • Before the command is actually executed, you will be asked to provide your login password. Linux stores passwords for a period of 15 minutes to make it easier to execute a series of consecutive commands.
Become Root in Ubuntu Step 3
Become Root in Ubuntu Step 3

Step 3. Use the prefix gksudo before executing a command that starts a program with a graphical user interface (GUI)

For security reasons, Ubuntu developers do not recommend using the "sudo" prefix to start GUI-enabled programs. In this case it is better to use the prefix gksudo followed by the command to start the program in question.

  • For example, typing the command gksudo gedit / etc / fstab displays the contents of the "fstab" file within the GEdit editor, a GUI-equipped text editor.
  • If you are using the KDE Window Manager, you must use the kdesudo prefix instead of gksudo.
Become Root in Ubuntu Step 4
Become Root in Ubuntu Step 4

Step 4. Simulate an environment with root access

If you are an experienced user who needs to log into a real system shell as root to run certain scripts, you can simulate this by using the sudo –i command. This command allows you to access the system and the root user variables as superuser.

  • Run the command sudo passwd root. This will create an authentication password for the root user, in other words the account will be "activated". It goes without saying that you shouldn't forget your newly created password for any reason.
  • Type the command sudo -i, then enter the root user's password as soon as you are prompted to do so.
  • The symbol that characterizes the command prompt will change from $ to #, indicating that you have successfully obtained access as the root user.
Become Root in Ubuntu Step 5
Become Root in Ubuntu Step 5

Step 5. Assign sudo access to another user

If you are setting up a user profile of another person who does not currently have root access to the computer, you can grant them this privilege by placing them in the "sudo" user group. To do this, run the command usermod -aG sudo username (replace the "username" parameter with the correct name of the account to be changed).

Method 2 of 2: Enable Root User Account Use

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

Step 1. Press the key combination Ctrl + Alt + T to open a "Terminal" window

For security reasons (and to prevent novice users from accidentally damaging the operating system), the root user account is disabled by default. To safely run a command as root, you should use the prefix

I sweat

or

gksudo

. If you absolutely need to access the system as a user (for example because a specific program you use for work requires it or because your computer is not shared with anyone else), you can enable the use of the root user by running some simple commands.

The creators of Ubuntu advise not to perform this procedure because enabling direct use of the root account puts the entire system at risk

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

Step 2. Type the command sudo passwd root, then press the Enter key

You will be asked to set up a new login password for the root user. For no reason in the world you will have to forget or lose this password.

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

Step 3. Enter your chosen password, then press the Enter key

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

Step 4. When prompted, enter the password again to confirm it is correct, then press the Enter key

The root user now has a login password set.

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

Step 5. Type the command su -, then press the Enter key

When prompted, enter the newly created password to display the root user's command prompt.

To disable the root account again, run the command sudo passwd -dl root

Advice

  • You should do everything possible to avoid logging into an Ubuntu system with the root user. The reason is that you would be able to run pretty much any command that requires computer administrator permissions, such as sudo or gksudo.
  • To access the system shell using another user, you can use the sudo –i command. For example, to become the user "Luca", type the command sudo –I Luca, then type your login password when prompted (not that of the user "Luca").

Recommended: