Advertisement
v1ral_ITS

create 2 root user accts or delete a root user

Jun 22nd, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.59 KB | None | 0 0
  1. 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.
  2.  
  3. This can be easily done by changing UID (user id) and GID (group id) in /etc/passwd file.
  4.  
  5. Also you will learn how to just add user to root group and i will explain how to delete user with root privileges.
  6.  
  7. 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.
  8.  
  9. 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.
  10.  
  11. 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.
  12.  
  13. Grant Root Privileges To New User
  14.  
  15.  Let’s say you need to create a new user and grant him root access to the server.
  16. 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).
  17.  
  18. Use the following commands to create a user john, grand him the same privileges as root and set him a password:
  19.  
  20. $ sudo useradd -ou 0 -g 0 john
  21. $ sudo passwd john
  22. Grant Root Privileges To Existent User
  23. Cool Tip: Dot the i’s and cross the t’s on file and folder permissions in Linux! Make it more clear! Read more
  24.  
  25. Perhaps you already have a user john and you want to grant him root privileges (make him a second root user):
  26.  
  27. $ grep john /etc/passwd
  28. john:x:1001:1001::/home/alice:/bin/sh
  29. For this, it is required to edit the file /etc/passwd and just change UID and GID to 0:
  30.  
  31. $ grep john /etc/passwd
  32. john:x:0:0::/home/john:/bin/sh
  33. Add User To Root Group
  34. If you just want to add john to root group, without granting him all root privileges, run the following command:
  35.  
  36. $ sudo usermod -a -G root john
  37. Delete User With Root Privileges
  38. Cool Tip: Log in to a remote Linux server without entering password! Set up password-less SSH login! Read more
  39.  
  40. You won’t be able to delete a user with UID 0 using userdel command:
  41.  
  42. $ sudo userdel john
  43. userdel: user john is currently used by process 1
  44. To delete him, firstly open the /etc/passwd file and change his UID.
  45.  
  46. For example, change the line:
  47.  
  48. john:x:0:0::/home/john:/bin/sh
  49. to something like:
  50.  
  51. john:x:1111:0::/home/john:/bin/sh
  52. After this, you’ll be able to delete user john with userdel command:
  53.  
  54. $ sudo userdel john
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement