How to add a user in linux and give root permission
- 2020-05-13 04:14:40
- OfStack
1. linux adds users and grants root permissions
1. To add users, first use adduser command to add a normal user. The command is as follows:
#adduser eric
// add 1 called eric The user
#passwd eric// Change the password
Changing password for user eric.
New UNIX password: // Enter your new password here
Retype new UNIX password: // Enter the new password again
passwd: all authentication tokens updated successfully.
2. Give root permission
Method 1: modify the /etc/sudoers file to find the following line and remove the previous comment (#)
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
Then modify the user to belong to the root group (wheel) with the following command:
#usermod -g root eric
After the modification, you can now log in with the eric account, and then use the command su to obtain the permission of root to operate.
Method 2: modify the /etc/sudoers file, find the following line, and add a line under root, as follows:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
eric ALL=(ALL) ALL
After the modification, you can now log in with the eric account, and then use the command sudo to obtain the permission of root to operate.
Method 3: strongly recommend this method, modify the /etc/passwd file, find the following line, and change the user ID to 0
As follows:
eric:x:0:33:eric:/data/webroot:/bin/bash
2. Management of Linux system user groups
Each user has one user group, and the system can centrally manage all users in one user group.
Different Linux systems have different rules for user groups,
For example, the user under Linux belongs to a user group with the same name, which is created at the same time as the user is created.
The management of user groups involves the addition, deletion, and modification of user groups. Group additions, deletions, and modifications are actually updates to /etc/group files.
1. Add a new user group using the groupadd command.
Grammar:
groupadd option user group
Options:
-g GID specifies the group id number of the new user group (GID).
-o 1 can be used with the -g option to indicate that the GID for a new user group can be the same as the GID for an existing user group on the system.
Case 1:
$ groupadd group1
Definition:
This command adds a new group group1 to the system with a group id of 1 on top of the current largest group id.
Example 2:
$ groupadd -g 101 group2
Definition:
This command adds a new group group2 to the system and specifies that the group id number for the new group is 101.
2. If you want to delete an existing user group, use the groupdel command.
Grammar:
groupdel user group
Case 1:
$ groupdel group1
Definition:
This command removes the group group1 from the system.
3. Modify the properties of the user group using the groupmod command.
Grammar:
groupmod option user group
Options:
-g GID specifies a new group id number for a user group.
Using the -o option with the -g option, the new GID for the user group can be the same as the GID for the system's existing user group.
-n new user group changes the name of the user group to a new name
Case 1:
$ groupmod -g 102 group2
Definition:
This command changes the group id number for group group2 to 102.
Example 2:
$ groupmod � g 10000 -n group3 group2
Definition:
This command changes the identification number of group group2 to 10000 and the group name to group3.
4. If a user belongs to multiple user groups at the same time, the user can switch between user groups so as to have the permissions of other user groups.
Users can switch to other user groups after logging in using the command newgrp, which takes the target user group as its argument.
Such as:
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
0
Definition:
This command switches the current user to the root user group, provided that the root user group is indeed the primary or additional group for that user.
Similar to the management of user accounts, the management of user groups can also be accomplished through integrated system management tools.
conclusion
The above is the whole content of this article, I hope the content of this article to your study or work can bring 1 definite help, if you have questions you can leave a message to communicate.