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
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
Warning: Before moving forward, read the comments below and DON’T FOLLOW THE STEPS FROM THIS ARTICLE if you don’t understand of what you are doing and what impact this may have!
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 (
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 john:x:1001:1001::/home/alice:/bin/sh
For this, it is required to edit the file
/etc/passwd and just change
$ grep john /etc/passwd john:x:0:0::/home/john:/bin/sh
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
$ sudo userdel john userdel: user john is currently used by process 1
To delete him, firstly open the
/etc/passwd file and change his
For example, change the line:
to something like:
After this, you’ll be able to delete user
$ sudo userdel john