Configuration Management for Users and Groups under Linux Operating System

  
                  Linux User and Group Management
User Management, the main job is to establish a legal user account, set and manage the user's password, modify the user account's attributes, and delete the deprecated user account if necessary. 1. Add a new user In the Linux system, only the root user can create a new user. The following command will create a new user with the login user1. # useradd user1 However, this user is not able to log in because the initial password has not been set yet, and the user without the password cannot log in to the system. By default, a new user home directory with the same username will be created in the /home directory. If you need to specify another user's home directory, you can use the following command: # useradd -d /home/xf user1 At the same time, the user will get a shell program when logging in: /bin/bash, and if you don't want this user to log in, You can also specify the user's shell program as: /bin/false, so that the user can not execute the command under Linux even if he logs in: # useradd -s /bin/false user1 In Linux, add a user at the same time A new group will be created, this group has the same name as the user, and this user is a member of the group. If you want the new user to belong to an existing group, you can use the following command: # useradd -g user user1 This user belongs to a member of the user group. And if you just want to belong to a group, you should use: # useradd -G user user1 After you have done this, you should also use the passwd command to set an initial password for it. 2. Delete a user To delete a user, simply use a simple command "userdel username". However, it is best to delete the files that are left on the system. You can use "userdel -r username" to do this. 3. Modify User Attributes In the previous section, we saw how to specify its user home directory when creating a new user, how to specify its shell, how to set the group it belongs to, and so on. A command is provided in Linux to implement: usermod -g group name -G group name -d user home directory -s user shell There is also a straightforward method, which is to modify the /etc/passwd file, in this file each The user occupies one line, its content is: Username: Password: User ID: Group ID: User's full name: User's home directory: User Shell However, it is worth noting that the password is usually replaced by an *, you Can't see it. 4. Add a group Remember that Linux files can set different access rights for people in the same group and non-groups? We can create user groups according to their needs: groupadd group name 5. delete a group Similarly, we sometimes need to delete a group, its command is the groupdel group name. 6. Modify group members If we need to add a user to a group, just edit the /etc/group file and write the username to the end of the group name. For example, to add the newuser user to the softdevelop group, just find the softdevelop line: softdevelop:x:506:user1,user2 and then add newuser at the end, forming: softdevelop:x:506:user1,user2,newuser Also, in Red Hat Linux also provides a graphical user management tool: userconf, which allows for more direct user management. Two important files: passwd and group
In the security mechanism of Linux, the two files /etc/passwd and /etc/group occupy a very important position. They control some important settings for Linux users and groups. ◆ /etc/passwd file description (used to set the user's properties) Vi /etc/passwd can be used to view the passwd file, each line is divided into 7 parts by a colon (":"), respectively: [username]: [Password]: [UID]: [GID]: [Identity Description]: [Home Directory]: [Login Shell] Where: [UID] Although the system is used to mark the file ownership, determine the various permissions of the logo, but this area The content is not required to be unique. An example of a more common and related security issue is a user account with multiple UIDs and GIDs of zero. Notice that there is a user imnotroot with UID and GID 0 in the last line of the file. Although it claims that it is not root, it has the same permissions as root because the system is not based on [username] but based on UID. And GID to divide the power of the user. Therefore, this situation undoubtedly buried a safe bomb for the system. However, when imnorroot does the lock screen and other operations, if its password is different from root, it will not be unlocked, because the system only finds the first user with UID 0 (naturally root), it is not Looked down - it is also unique when the UID. [GID] The default group ID of the user. This ID can be found in the file /etc/group. <Note>: [UID] and [GID] are less than 500. Generally, the system retains itself and does not identify the common users and groups. Therefore, newly added users and groups are generally UIDs and GIDs greater than 500. ◆ /etc/group file description vi /etc/group View its contents It is divided into four parts: [group name]: [password field]: [GID]: [group member table]

Copyright © Windows knowledge All Rights Reserved