First, user account management
1. Add a new user account
Command format: Useradd option user name
The options have the following meanings:
-C Comment Specifies an annotative description.
The-D directory specifies the home directory, and if this directory does not exist, the-m option can be used to create the master directory.
The-G user group specifies the user group to which the user belongs.
-G user Group, user group specifies the additional group to which the user belongs.
-S Shell file specifies the user's login shell.
-u user number specifies the user's user number, and if you have the-o option, you can reuse the other user's identification number.
Example 1:
> Useradd–d/usr/tom-m Tom
This command creates a user, Tom,
Where the-D and-m options are used to generate a home directory for the login Tom/usr/tom (/usr is the parent directory where the default user home directory resides).
Example 2:
> Useradd-s/bin/sh-g group–g adm,root Gem
This command creates a new user gem, which is the login shell of/bin/sh, which belongs to the group user groups, and also to the ADM and root user groups, where group user groups are their primary groups.
2. Delete Account
Deleting the user account is to delete the user record in the system files such as/etc/passwd, and delete the user's home directory if necessary.
Command format: Userdel option user name
The common option is-r, which is to remove the user's home directory.
3. Modify your Account
Modify user account is based on the actual situation to change the user's relevant attributes, such as user number, home directory, user group, login shell and so on.
Command format: Usermod option user name
Common options include-C,-D,-M,-G,-G,-S,-u, and-O, which are the same as the options in the Useradd command
Cases:
> Usermod-s/bin/ksh-d/home/z–g developer Tom
This command modifies the user Tom's login shell to Ksh, the home directory to/home/z, and the user group to developer.
4. User Password Management
User account has just been created without a password, but is locked by the system, can not be used, it must be given a password before use, even if the specified empty password
The shell command that specifies and modifies the user's password is passwd. Superuser can specify a password for himself and other users, and the normal user can only use it to modify their password.
Command format: passwd option user name
Option meaning:
-L locks the password, which disables the account.
-u password to unlock.
-D make the account no password.
-F forces the user to modify the password the next time they log on.
If the default user name, the password for the current user is modified.
For example: Assuming the current user is Sam, the following command modifies the user's own password:
> passwd
If you are a superuser, you can specify any user's password in the following form
> passwd sam
Second, user group management
Each user has a user group, and the system can centrally manage all users in a single user group.
Different Linux systems provide a different set of user groups, as users under Linux belong to a user group with the same name, which is created at the same time as the user is created.
1. New User groups
Command format: Groupadd option user Group
Available options:
-G GID Specifies the group identification number (GID) of the new user group.
-O is commonly used with the-G option, which means that the GID of the new user group can be the same as the GID of the user group already in the system.
Example 1:
> Groupadd group1
This command adds a new group group1 to the system, and the group identification number of the new group is added 1 on the basis of the currently existing maximum group identification number.
Example 2:
> Groupadd-g 101 group2
This command adds a new group group2 to the system, specifying that the group identification number for the new group is 101.
2. Delete a user group
Format: Groupdel user Group
3. Modify user Groups
Format: Groupmod option user Group
Option meaning:
-G GID Specifies a new group identification number for the user group.
The-O is used in conjunction with the-G option, and the user group's new GID can be the same as the GID of the user group already in the system.
-N New user Group change user group name to new name
Example 1:
> Groupmod-g 102 group2
This command modifies the group ID number of group group2 to 102.
Example 2:
> Groupmod–g 10000-n group3 group2
This command changes the identification number of the group group2 to 10000 and the group name to Group3
4. If a user belongs to more than one user group at the same time, the user can switch between groups of users so that they have permissions for the other user groups. After logging in, the user can switch to another user group using the command Newgrp, which is the target user group
> Newgrp Root
This command switches the current user to the root user group, provided that the root user group is really the user's primary or additional group. Similar to the management of user accounts, the management of user groups can also be accomplished through integrated system management tools.
Management of users and user groups under Linux