Linux user management to read, write, execute actions as permissions, in the user group as a unit, limit user behavior. For file operations, you can restrict which of the read, write, or execute, or restrict the permissions of the file owner, group users, and users outside the group.
Therefore, to establish a user, it is best to first determine the group in which they are located.
One, user group operation
1. Create a user group--groupadd
#新增deploy组 Groupadd Deploy
2. Modify user groups--groupmod
#将用户组deploy更名为deploy1 -N deploy1 Deploy
Note that the existing deploy group is renamed to Deploy1
3. Delete user group--groupdel
#删除用户组deploy1 Groupdel deploy1
4. View user Groups--groups/etc/group
Groups can only view the group that the current user is in, and the following is the group where the root user resides.
Reference
# groups Root bin daemon Sys adm disk wheel
To see all user group information, see/etc/group directly:
Reference
# cat/etc/Group root:x:0: root bin:x:1: Root,bin,daemon daemon:x:2 : Root,bin,daemon sys:x:3
Second, user operation
1. Create User--useradd
Reference
# Useradd Usage:useradd [options] LOGIN options:-B,--Base-dir Base_dirBaseDirectory forTheNewUser account Home directory-C,--comment commentSetThe GECOS field forTheNewUser Account-D,--home-dir home_dir home Directory forTheNewUser Account-D,--defaults print or save modifieddefaultuseradd Configuration-E,--expiredate expire_dateSetAccount expiration date to Expire_date-F,--inactive inactiveSetpassword inactive after expiration to inactive-G,--gid Group Force use Group forTheNewUser Account-G,--groups groups list of supplementary groups forTheNewUser Account-H,--help display ThisHelp message and exit-K,--Skel Skel_dir Specify an alternative Skel directory-K,--key Key=value overrides/etc/login.defs Defaults-M,--create-home create home directory forTheNewUser Account-L, DoNot add user to Lastlog database file-M, DoNot create user's home directory (overrides/etc/login.defs)-r, create system account-O,--non-unique allow create user with duplicate (non-unique) UID-p,--password password use encrypted password forTheNewUser Account-S,--shell shell the login shell forTheNewUser Account-U,--uid UID Force use the UID forTheNewUser Account-Z,--selinux-user seuser use a specific seuser forThe SELinux user mapping
New user deploy, located in the Deploy group, for deployment work:
#-Group G user -G deploy deploy
New user Nginx, located in www group, and can not be logged in to start Nginx:
Useradd-s/sbin/nologin-g www nginx
To set a password for user deploy:
Reference
fornew
Create a new user test, located in the WWW group, and set a password of 1234567890 for it:
1234567890 Test
2. Modify User--usermod gpasswd
Reference
# usermod Usage:usermod [options] LOGIN options:-A,--Append append the user to the supplemental GROUPS >-G)-C,--comment commentNewvalue of the GECOS field-D,--home Home_dirNewHome Directory forThe user account-E,--expiredate expire_dateSetAccount expiration date to Expire_date-F,--inactive inactiveSetpassword inactive after expiration to inactive-G,--gid Group Force use Group as NewPrimary Group-G,--groups groupsNewList of supplementary GROUPS-H,--help display ThisHelp message and exit-L,--login New_loginNewvalue of the login name-L,--Lock LockThe user account-M,--move-home move contents of the home directory to theNewLocation ( use only with-d)-O,--non-unique allowusingDuplicate (non-unique) UID-p,--password password use encrypted password forTheNewPassword-S,--shell shellNewLogin Shell forThe user account-U,--uid uidNewUid forThe user account-U,--unlock unlock the user account-Z,--selinux-userNewSELinux User Mapping forThe user account
Set the user test login directory to/home/test and add it to the WWW group:
usermod-d/home/test-g www Test
Append user test to the Deploy group:
Usermod-a-G Deploy test
Note: If you do not have-a, the user's group will be changed directly, removing the user from the original group!
At this time with GPASSWD is more safe!
GPASSWD-A Test Deploy
Remove the user test from the WWW group:
gpasswd-d Test www
3. Delete User--userdel
Delete the user test and remove its login directory:
Userdel-r Test
Linux Command collation-user management