【linux】用户和组的管理:添加、修改、删除(useradd usermod userdel groupadd groupdel)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010168781/article/details/87793772

一、用户

1、添加
$ useradd -h
Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
  -b, --base-dir BASE_DIR       base directory for the home directory of the  new account
  -c, --comment COMMENT        加上备注文字,备注文字保存在passwd的备注栏中。
  -d, --home-dir HOME_DIR       用户的家目录
  -D, --defaults                显示或更改默认值
  -e, --expiredate EXPIRE_DATE  指定账号的失效日期,日期格式为MM/DD/YY,例如06/30/12。缺省表示永久有效。
  -f, --inactive INACTIVE       指定在密码过期后多少天即关闭该账号。如果为0账号立即被停用;如果为-1则账号一直可用。默认值为-1.
  -g, --gid GROUP               指定用户所属的群组。值可以使组名也可以是GID。用户组必须已经存在的,期默认值为100,即users
  -G, --groups GROUPS          指定用户所属的附加群组。
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           use this alternative skeleton directory
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             自动创建用户的家目录。
  -M, --no-create-home          不创建用户的家目录
  -N, --no-user-group           不创建与用户同名的组
  -o, --non-unique              允许创建具有重复(非唯一)UID的用户
  -p, --password PASSWORD       新帐户的加密密码
  -r, --system                  创建一个系统帐户
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL            指定用户登入后所使用的shell。默认值为/bin/bash。
  -u, --uid UID                 指定用户ID号。该值在系统中必须是唯一的。0~499默认是保留给系统用户账号使用的,所以该值必须大于499。
  -U, --user-group              创建与用户同名的组
  -Z, --selinux-user SEUSER     为SELinux用户映射使用特定的SEUSER

例子:

sudo useradd -d /home/haha -m -G sudo haha
2、修改
$ usermod -h
Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         更改备注文字,备注文字保存在passwd的备注栏中。
  -d, --home HOME_DIR           更改家目录
  -e, --expiredate EXPIRE_DATE  修改用户到期日期
  -f, --inactive INACTIVE       将过期后的密码设置为非活动
  -g, --gid GROUP              强制使用组作为新的主组
  -G, --groups GROUPS           把用户追加到某些组中,仅与-a选项一起使用
  -a, --append                  把用户追加到某些组中,仅与-G选项一起使用
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         修改登陆名
  -L, --lock                    锁定用户帐户
  -m, --move-home               将主目录的内容移动到新位置,和-d一起使用
  -o, --non-unique              允许使用重复(非唯一)UID
  -p, --password PASSWORD       更改密码
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             重置shell
  -u, --uid UID                 重置UID
  -U, --unlock                  解锁用户
  -v, --add-subuids FIRST-LAST  添加从属uid
  -V, --del-subuids FIRST-LAST  删除从属uid
  -w, --add-subgids FIRST-LAST  添加从属gid的范围
  -W, --del-subgids FIRST-LAST  删除从属gids
  -Z, --selinux-user SEUSER     new SELinux user mapping for the user account

3、删除

$ userdel -h
Usage: userdel [options] LOGIN

Options:
  -f, --force                   强制删除文件,即使不属于用户
  -h, --help                    display this help message and exit
  -r, --remove                  删除家目录和邮件
  -R, --root CHROOT_DIR         directory to chroot into
  -Z, --selinux-user            remove any SELinux user mapping for the user

二、组

1、添加
$ groupadd -h
Usage: groupadd [options] GROUP

Options:
  -f, --force                   如果组已经存在,则成功退出;如果GID已经使用,则取消-g
  -g, --gid GID                 重新设置组id
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              允许创建具有重复(非唯一)GID的组
  -p, --password PASSWORD       为新组使用此加密密码
  -r, --system                  创建一个系统帐户
  -R, --root CHROOT_DIR         更改root目录

2、更改
$ groupmod -h
Usage: groupmod [options] GROUP

Options:
  -g, --gid GID                 更改组ID
  -h, --help                    display this help message and exit
  -n, --new-name NEW_GROUP      更改组名
  -o, --non-unique              允许使用重复的(非唯一的)GID
  -p, --password PASSWORD       更改组密码
  -R, --root CHROOT_DIR         directory to chroot into
3、删除
$ groupdel -h
Usage: groupdel [options] GROUP

Options:
  -h, --help                    display this help message and exit
  -R, --root CHROOT_DIR         directory to chroot into

猜你喜欢

转载自blog.csdn.net/u010168781/article/details/87793772