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 commands with root privileges) is necessary for many tasks. Into this article we will learn how to create a user with root permission 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 ~]#

 

 

3 thoughts on “How to Create a user with root permission in Linux”

  1. I needed to write you a little word in order to say thanks a lot over again over the lovely suggestions you have featured in this case. It was simply remarkably open-handed of people like you to allow unhampered just what many people could have advertised as an electronic book to help make some money on their own, primarily seeing that you might have done it in the event you considered necessary. These thoughts in addition served like the great way to realize that many people have the identical eagerness the same as my very own to know the truth somewhat more pertaining to this problem. I believe there are some more enjoyable periods up front for many who look into your blog.
    caitlynPl

  2. Pretty portion of content. I simply stumbled upon your weblog and in accession capital to say that I acquire actually enjoyed account your blog posts. Any way I will be subscribing for your augment or even I fulfillment you get admission to persistently quickly.

Leave a Reply

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