Thursday, 26 May 2016

HowTo : Create USER with ROOT Privileges in Linux

From this article you'll learn how to create a user with root privileges or grant root permissions to an existing user by setting User and Group IDs.
I'll also explain how to delete a user with root privileges (with UID 0 in particular).
Actually it 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 items as superuser, instead of using the methods below.

Create a USER Account with ROOT Privileges

Lets say we need to add a new user and grand him root privileges.
Use the following commands to create the new user john, grand him the same privileges as root and set him a password :
# useradd -ou 0 -g 0 john
# passwd john
We've just created the user john, with UID 0 and GID 0, so he is in the same group and has the same permissions as root.

Grant ROOT Privileges to an Existing USER

Perhaps you already have some user john and you would like to give root permissions to a normal user.
# grep john /etc/passwd
john:x:1001:1001::/home/john:/bin/shEdit /etc/passwd file and grant root permissions to the user john by changing User and Group IDs to UID 0 and GID 0 :
# $ grep john /etc/passwd
john:x:0:0::/home/john:/bin/sh

Delete a USER Account with UID 0

You won't be able to delete second root user with another UID 0 using userdel command.
# userdel john
userdel: user john is currently used by process 1

To delete user john with UID 0, open /etc/passwd file and change john's UID.
For example, change the line :
john:x:0:0::/home/john:/bin/sh
to something like :
john:x:1111:0::/home/john:/bin/sh
Now, you'll be able to delete user john with userdel command :
# userdel john

No comments:

Post a Comment