How to Create a user with root permission in Linux.

Create a user with root permission in Linux.

On every Linux system, the root account is a special user that has administrative rights. Logging in as root (or executing commandswith root privileges) is necessary for many tasks. Into this article we will learn how to create a user with root privileges or grant root permissions to an existing user by setting User and Group IDs and we will also learn how to delete a root permission granted user.
Actually this is not a good idea to give all the permissions of root to a non-root user, so use the sudo command on the production servers to run commands as super user, instead of using the non root user with root permission.


Warning : Giving a non-root user all the permissions of root is very dangerous, because the non-root user will be able to do literally anything that could cause a big trouble if account is hijacked.


How to Create a new user account with Root Privileges or Permissions.

Lets First step is we have to add a new user into the system and grand him all root permission.
Use the following commands to create the new user raj and give him the same privileges as root and set a new password :

        # useradd -ou 0 -g 0 raj
        # passwd raj


[root@linuxelearn ~]# useradd -ou 0 -g 0 raj

[root@linuxelearn ~]# passwd raj
Changing password for user raj
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
[root@linuxelearn ~]#


Now we have just created the user raj, with UID 0 and GID 0, so that user in the same group and has the same permissions as root. Using this raj user you can perform all root commands without any warning and error.

How to give Root Permission to an existing user in Linux.

Perhaps you already have another normal user use that user in my case I have normal user named as sam and you would like to give root permissions to this normal user.
Frist check details of sam user. It will show following output.

# grep sam /etc/passwd


[root@linuxelearn ~]# grep sam /etc/passwd
sam:x:506:506::/home/sam:/bin/sh


Now edit /etc/passwd file and give root permissions to the user sam by changing User and Group IDs to UID 0 and GID 0 :

Then check detail info it will show following output.

#  grep sam /etc/passwd


[root@linuxelearn ~]# grep sam /etc/passwd
sam:x:0:0::/home/sam:/bin/sh


How to delete a user account with UID 0 or root permission granted user.

You can't delete second root user with another UID 0 using userdel command.

# userdel sam


[root@linuxelearn ~]# userdel sam
userdel: user sam is currently used by process 1


It will show above massage.

To delete user sam with UID 0, open /etc/passwd file and change sam user UID.
For example,


[root@linuxelearn ~]# grep sam /etc/passwd
sam:x:0:0::/home/sam:/bin/sh


Sam user UID is 0 change it into as following:


[root@linuxelearn ~]# grep sam /etc/passwd
sam:x:601:0::/home/sam:/bin/sh


Now, you'll be able to delete user sam with userdel command :

# userdel sam

[root@linuxelearn ~]#userdel sam
[root@linuxelearn ~]#



I hope you enjoyed reading this post.... 

Post a Comment