How to Give Root Privileges to a User in Linux

ways to give root privileges to a user on linux

The “root” super user is the king of users in Linux/Unix. Having root access grants full and unlimited access to the Linux box.

In this tutorial, I will show you how to allow root access to a user in a Linux system. Typically, root level access is used in system administration. So it is always a pain to give root access to other users. You need to be careful and should withdraw the access once the need to do so is over.

According to Linux file system permissions, root or super user has full permission to read(r), write (w) and execute(x)  any file. By default root user id is '0'.

I am going to create two users namely user1 and user2. Then I will show you how to give root access to 'user1'.

Method  1: Adding to Root Group using usermod

Let see how we can grant normal user root access by adding to root group.

# adduser user1
# adduser user2
# groupadd test

These are the groups I have in my Linux box.

# groups
root bin daemon sys adm disk wheel

I am going to add user1 to root group as follows:

# usermod -G root user1

The command given below provides the existing user with the root privilege

# usermod -g 0 -o root_user

Method 2: Adding to Root Group using Useradd Command

I have added a new user, 'user3' to the root group using one single command:

# useradd -m -G root user3
# groups user3
user3 : user3 root

Another option using useradd command

useradd -c “Imitation Root” -d /home/root_user -m -k /etc/skel -s /bin/bash -u 0 -o -g root root_user

Method 3: Editing /etc/passwd file

Edit /etc/passwd for the particular user. Change the user's UID and GID to '0'. This will give root permissions to user.

root:x:0:0:root:/root:/bin/bash
temproot:x:128:128:temproot

Now, temproot user should have root privilege:

root:x:0:0:root:/root:/bin/bash
temproot:x:0:0:temproot

Note: This is not the recommended method for granting root access

Method 4: Setting as Sudo User

The sudo configuration file is /etc/sudoers and you can edit this file using visudo command: # visudo.

Using visudo protects from conflicts and guarantees that the right syntax is used.

To give full access to specific users

Add the entry given below in the file:

bob, tom ALL=(ALL) ALL

Following this method is not a good idea because this allows both bob and tom to use the su command to grant themselves permanent root privileges. Thereby skipping the command logging features of sudo.

Granting access to specific files to one particular user

This entry allows bob and all the other members of the group operator to gain access to all the program files in the /sbin and /usr/sbin directories, as well as the privilege of running the command /usr/oracle/backup.pl.

bob, %operator ALL= /sbin/, /usr/sbin, /usr/oracle/backup.pl

If you have any questions or thoughts to share on this topic, use the feedback form.

Read Also:

Bobbin Zachariah 1:18 pm

Comments

Your email address will not be published. Required fields are marked *

8 Comments

  1. I tried method 3 and found it to be dangerous. After making the suggested changes, I was not able to login to my user. Please re check the procedure again

    1. If you do the 3rd option, it will turn the user into a root user, thus not allowing any remote connections

  2. About Method 4.
    I tried the following command visudo and which took me to /etc/sudoer in edit mode, I entered the details under
    root (ALL=ALL)ALL. I entered the user under this.

    But post this I was not able to exit the file even after using esc Key and then selecting :wq!

    It kept on entering the values whatever I was typing. FInally I had to kill the terminal to come out of it.

    Please suggest on that.

  3. I have only one user. Was always changing to root in a terminal by typing "sudo -s". Does this means that my existing user is having root privileges or am I just switching to root for the session?

    1. Hi SPT,

      When you use 'sudo -s' it is switching to gain root access but don't touch root's environmental files. ie your home will not be the root home. This is commonly used when users need root shell for easy command execution.

    2. you are just switching to root user that dosent't means the user has root privileges if you want to check the user has root privileges try to edit any file or folder in the root directory when you get acces denied you don't have the root privileges.