【2014-04-27】linux的用户管理命令

发布时间:2026/8/18 13:29:10
【2014-04-27】linux的用户管理命令 [历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2014-04-27 标题linux的用户管理命令分类操作系统 / linux 标签linux·常用命令linux的用户管理命令useradd添加用户useradd帮助文档useradd使用示例groupadd添加用户组帮助文档及示例查看用户userdel删除用户帮助文档及示例查看用户组groupdel删除用户组useradd添加用户useradd帮助文档root:~# useradd -h用法useradd[选项]登录useradd-Duseradd-D[选项]选项 -b, --base-dir BASE_DIR 新账户的主目录的基目录 -c,--commentCOMMENT 新账户的 GECOS 字段 -d, --home-dir HOME_DIR 新账户的主目录 -D,--defaults显示或更改默认的useradd配置 -e,--expiredateEXPIRE_DATE 新账户的过期日期 -f,--inactiveINACTIVE 新账户的密码不活动期 -g,--gidGROUP 新账户主组的名称或 ID -G,--groupsGROUPS新账户的附加组列表 -h,--help显示此帮助信息并推出 -k,--skelSKEL_DIR 使用此目录作为骨架目录 -K,--keyKEYVALUE 不使用 /etc/login.defs 中的默认值 -l, --no-log-init 不要将此用户添加到最近登录和登录失败数据库 -m, --create-home 创建用户的主目录 -M, --no-create-home 不创建用户的主目录 -N, --no-user-group 不创建同名的组 -o, --non-unique 允许使用重复的UID创建用户 -p,--passwordPASSWORD 加密后的新账户密码 -r,--system创建一个系统账户 -R,--rootCHROOT_DIRchroot到的目录 -s,--shellSHELL新账户的登录 shell -u,--uidUID新账户的用户 ID -U, --user-group 创建与用户同名的组 -Z, --selinux-user SEUSER 为 SELinux 用户映射使用指定 SEUSERuseradd使用示例rootcstriker1407-ubuntu:~# useradd test1rootcstriker1407-ubuntu:~# useradd test2 -p passwd2rootcstriker1407-ubuntu:~# mkdir /home/test3rootcstriker1407-ubuntu:~# useradd test3 -p passwd3 -d /home/test3groupadd添加用户组帮助文档及示例rootcstriker1407-ubuntu:/home/cstriker1407# groupadd -h用法groupadd[选项]组 选项: -f,--force如果组已经存在则成功退出 并且如果 GID 已经存在则取消-g-g,--gidGID 为新组使用 GID -h,--help显示此帮助信息并推出 -K,--keyKEYVALUE 不使用 /etc/login.defs 中的默认值 -o, --non-unique 允许创建有重复 GID 的组 -p,--passwordPASSWORD 为新组使用此加密过的密码 -r,--system创建一个系统账户 rootcstriker1407-ubuntu:/home/cstriker1407# groupadd testgrouprootcstriker1407-ubuntu:/home/cstriker1407# useradd test4 -g testgroup查看用户rootcstriker1407-ubuntu:/home/cstriker1407# cat /etc/passwd。。。。。 。。。。。 test1:x:1001:1001::/home/test1:/bin/sh test2:x:1002:1002::/home/test2:/bin/sh test3:x:1003:1003::/home/test3:/bin/sh test4:x:1004:1004::/home/test4:/bin/shuserdel删除用户帮助文档及示例rootcstriker1407-ubuntu:/home/cstriker1407# userdel -h用法userdel[选项]登录 选项 -f,--force即使不属于此用户也强制删除文件 -h,--help显示此帮组文件并退出 -r,--remove删除主目录和邮箱 rootcstriker1407-ubuntu:/home/cstriker1407# userdel -fr test1userdel警告无法删除 /var/mail/test1没有那个文件或目录 userdel未找到 test1 的主目录“/home/test1” rootcstriker1407-ubuntu:/home/cstriker1407# userdel -fr test2userdel警告无法删除 /var/mail/test2没有那个文件或目录 userdel未找到 test2 的主目录“/home/test2”查看用户组rootcstriker1407-ubuntu:/home/cstriker1407# cat /etc/group。。。。。 testgroup:x:1004:groupdel删除用户组rootcstriker1407-ubuntu:/home/cstriker1407# groupdel用法groupdel 组 rootcstriker1407-ubuntu:/home/cstriker1407# groupdel testgroup