Linux User and group management
Group Management
groupadd命令:添加组 groupadd 选项 group_name -g GID :指定GID;默认是上一个组的GIDS+1 -r 创建系统组; groupmod命令修改组属性 groupmod 选项 GROUP -g 修改GID -n 修改组名 groupdel:删除组 groupdel 组名
User Management
useradd命令 选项 登录名 -u,--uid:指定UID; -g,--gid GROUP:指定基本组ID,此组得事先存在; -G,--groups GROUP1 [,GROUP2,...]:指明用户所属的附加组,多个组之间有逗号分隔 -c,--comment COMMENT:指明注释信息; -d,--home HOME_DIR:以指定的路径为用户的家目录:通过复制/etc/skel目录并重命名实现,如果指定的路径存在,则不会为用户复制环境配置文件; -s,--shell SHELL:指定用户的默认shell,可用的所有shell列表存储在/etc/shells文件中; -r,--system:创建系统用户;
注意:创建用户时的诸多默认设定配置文件为/etc/login.defs useradd -D :显示创建用户的默认配置: useradd -D 选项:修改默认选项的值; 修改的结果保存于/etc/default/useradd文件中;
Modify a user's properties
Usermod command: Modify user Properties
usermod [Options] Login name
-u,--uid UID: Modifying the UID of the user
-G,--GID Group; Modify the user's base group
-G,--groups Group: Modifies the additional group to which the user belongs: The original additional group will be overwritten;
-A,--append: used in conjunction with-G to append new additional groups to the user;
-c,--comment: Modify user's comment information;
-d,--home Home_dir: Modify the user's home directory, the user's original files will not be transferred to the new directory;
-m,--move-home: can only be used with the-D option to convert the original home directory to a new home directory;
-l,--login new_login: Modify user Name
-s,--shell Shell: Modifying the user's default shell
-L,--Lock: Locks the user's password, which is added before the user's original password string!
-U,--unlock: Unlock user password, coming soon! Delete
Usedel command: Delete user
Userdel [Options] Login userdel-r: Delete the user and delete their home directory;
Modify Password command
passwd command:
(1) passwd: Modify the user's own password;
(2) passwd USERNAME: Modify the password of the specified user, but only root has this permission;
-l,-u: Locking and unlocking the user;
-D: Clear the user password string;
-e Date: Expiration period, date;
-I days: inactivity period;
-N days: The minimum period of use of the password;
-X days: The maximum age of the password;
-W days: Warning period;
--stdin:echo "PASSWORD" | passwd--stdin USERNAME
- GPASSWD command:
GPASSWD [options] Group name/etc/gshadow
-a USERNAME: adding users to a group
-D USERNAME: Removing users from a group
- NEWGRP command:
Temporarily toggles the specified group into a basic group; NEWGRP-group name
- Chage command:
Change the password expiration information for a user
Chage option Login name-d-e-w-m-M
- ID Command:
Displays the user's valid ID;
-U: Displays only valid UID;
-G: Displays only the user's base group ID;
-G: Displays only the ID of the group to which the user belongs;
-N: Displays only names, not IDs;
- SU command: Switch user
Logon switching: Re-initialized by reading the target user's configuration file
Su-username
Su-l USERNAME
Non-logon switchover: Initialization of the target user's profile is not read
Su Usernamehu
Note: Administrators can switch to other users without a password;
-C ' command ': The command specified here is only run as the specified user;
Several other commands: Chsh,chfn,finger,whoami; PWCK;GRPCK, ""
Linux User and Group management commands