you will be able to login to the linux machine via ssh, and you will be able to change the uid and group to the “broken” user. So if you have a backup user that haves root privileges in visudo. The correct way to add a user with root privileges is adding the user the normal way, useradd -m user, and then add privileges with visudo to the user. Via tty you can login with any of the users, even root. So you will have to login to the linux machine via tty (this is the only way if you don`t have a correctly added backup user on the linux machine). If you add a user with uid 0 to group uid 0, and you set in sshd_config AllowRootLogin NO, you`re access will be denied. The only way is to successful login to the linux machine, if you login via ssh or tty. Since noone elaborate how to undo this broken way of adding users, I will. To something like: john:x:1111:0::/home/john:/bin/shĪfter this, you’ll be able to delete user john with userdel command: $ sudo userdel john To delete him, firstly open the /etc/passwd file and change his UID.įor example, change the line: john:x:0:0::/home/john:/bin/sh Userdel: user john is currently used by process 1 You won’t be able to delete a user with UID 0 using userdel command: $ sudo userdel john 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Ĭool Tip: Log in to a remote Linux server without entering password! Set up password-less SSH login! Read more → John:x:0:0::/home/john:/bin/sh Add User To Root Group 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įor this, it is required to edit the file /etc/passwd and just change UID and GID to 0: $ grep john /etc/passwd $ sudo passwd john Grant Root Privileges To Existent UserĬool Tip: Dot the i’s and cross the t’s on file and folder permissions in Linux! Make it more clear! Read more → 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 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). Let’s say you need to create a new user and grant him root access to the server. 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 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.Ĭheck 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. This can be easily done by changing UID (user id) and GID (group id) in /etc/passwd file.Īlso you will learn how to just add user to root group and i will explain how to delete user with root privileges.Īctually 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. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |