HowTo: Grant Root Access to User – Root Privileges – Linux

From this article you’ll learn how to create a user in Linux and grant root access to him or how to grant root privileges to already existent user.

This can be easily done by changing UID (user id) and GID (group id) in /etc/passwd file.

Also you will learn how to just add user to root group and i will explain how to delete user with root privileges.

Actually it is not a good idea to give all the privileges of root to a non-root user and outside the test environment i would not recommend to have multiply superusers.

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.

Check SSH Server Settings: If you have disabled root access in SSH server settings, by setting PermitRootLogin no in /etc/ssh/sshd_config – you won’t be able to login if your user has UID 0.

Grant Root Privileges To New User

Let’s say you need to create a new user and grant him root access to the server.

To create a user with exactly the same privileges as root user, we have to assign him the same user ID as the root user has (UID 0) and the same group ID ( GID 0).

Use the following commands to create a user john, grand him the same privileges as root and set him a password:

$ sudo useradd -ou 0 -g 0 john
$ sudo passwd john

Grant Root Privileges To Existent User

Cool Tip: Dot the i’s and cross the t’s on file and folder permissions in Linux! Make it more clear! Read more →

Perhaps you already have a user john and you want to grant him root privileges (make him a second root user):

$ grep john /etc/passwd

For this, it is required to edit the file /etc/passwd and just change UID and GID to 0:

$ grep john /etc/passwd

Add User To Root Group

If you just want to add john to root group, without granting him all root privileges, run the following command:

$ sudo usermod -a -G root john

Delete User With Root Privileges

Cool Tip: Log in to a remote Linux server without entering password! Set up password-less SSH login! Read more →

You won’t be able to delete a user with UID 0 using userdel command:

$ sudo userdel john
userdel: user john is currently used by process 1

To delete him, firstly open the /etc/passwd file and change his UID.

For example, change the line:


to something like:


After this, you’ll be able to delete user john with userdel command:

$ sudo userdel john

7 Replies to “HowTo: Grant Root Access to User – Root Privileges – Linux”

  1. “For this, it is required to edit the file /etc/passwd and just change UID and GID to 0”
    Baaaad idea. Much regret. Undo, undo?!!

      1. ntfs@brix:~$ ssh -l pi
        pi@‘s password:
        Permission denied, please try again.
        pi@‘s password:
        Permission denied, please try again.
        – – –
        Nice explanation?)

  2. It is prohibited to have to users with ID 0 in passwd file. Strange things then happens since linux messes users with the same ID.

  3. After lots of searching finally found what i was looking for. Thankyou for sharing the post.

  4. That is awesome article! you mentioned all required points not only how to create user. don’t stop blogging man!

  5. Do not use that F*ING decision, after i do that, my server did not accept any accesses

Leave a Reply