Linux Add and remove user groups
1. Build Users:
Useradd Test Add user test
passwd test to set the password for test
2. Establishment of Working groups
Groupadd Test Add test Group
Useradd–d/usr/sam-m Sam
This command creates a user Sam,
Where the-D and-m options are used to generate a home directory for the login Sam/usr/sam (/usr is the parent directory where the default user home directory resides).
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.
3. Add a workgroup while creating a new user
Useradd-g test test1 Add user test1 and add to test group
Note:-G belongs to group-D home directory-S Shell
4. Add a group to an existing user
USERMOD-G groupname username
The Usermod parameter and the Useradd parameter are basically the same
or Gpasswd-a user Group
5. Temporarily close the User:
The second field (password) that belongs to the user in the/etc/shadow file is preceded by a *, and you want to restore the user and remove the *.
Or, use the following command to close the user account:
passwd test-l
Re-release: passwd test-u
6. Permanently delete user accounts
Userdel Test
Userdel-r Test Delete user and user's home directory
Groupdel Test
7. Remove a user from a group
Edit/etc/group Find group1 the line, delete the
Or: gpasswd-d Group
8. Display user information:
Groups viewing groups to which a user belongs
ID user view the group to which the user belongs
9. View all users in a group
grep ' Test '/etc/group the group ID of the test group from the group
grep 1000/etc/passwd 1000 for test gid
10. Configuration files related to users and user groups
/ETC/PASSWD User-related profiles
/etc/shadow shadow files related to the user
/etc/group configuration files associated with a group
/etc/gshadow shadow files related to user groups
One./etc/skel Catalogue
/etc/skel directory is usually a directory of user startup files, this directory is controlled by root permissions, when we add users, the files in this directory are automatically copied to the newly added user's home directory, the files under the/etc/skel directory are hidden files, It is similar to the. file format; We can provide users with a unified, standard, Default user environment by modifying, adding, and deleting files in the/etc/skel directory;
/etc/skel directory files, generally we use the Useradd and AddUser command to add Users (user), the system automatically copied to the new Add users (user) in the home directory, if we modify the/etc/passwd to add users, We can create the user's home directory by ourselves, then copy the files under/etc/skel to the user's home directory, then use Chown to change the owner of the new user's home directory;
A. /etc/login.defs configuration file;
/etc/login.defs files are some planning when creating a user, such as when creating a user, whether the home directory, the UID and GID range, the user's deadline, and so on, can be defined by root;
./etc/default/useradd file;
The rule file when adding user through useradd;
# useradd defaults file
group=100
Home=/home Note: The user's home directory is built in/house;
Inactive=-1 Note: Whether to enable account expiration, 1 means not enabled;
Expire= Note: Account termination date, do not set the indication is not enabled;
Shell=/bin/bash Note: The type of shell used;
Skel=/etc/skel Note: By default, add the user's directory default file location, that is, when we add users with AddUser, the files in the user's home directory are copied from this directory in the past;
Linux User Management