Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- john:x:1001:1001::/home/alice:/bin/sh
- For this, it is required to edit the file /etc/passwd and just change UID and GID to 0:
- $ 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 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:
- john:x:0:0::/home/john:/bin/sh
- to something like:
- john:x:1111:0::/home/john:/bin/sh
- After this, you’ll be able to delete user john with userdel command:
- $ sudo userdel john
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement