deluser 命令在 CentOS 系统中用于删除用户账户及其相关文件。以下是 deluser 命令的详细用法:
deluser [选项] 用户名
-r 或 --remove-home:删除用户的主目录及其内容。-f 或 --force:强制删除用户账户,即使该账户正在使用中。-g 或 --group:删除用户所属的组。-a 或 --all:删除用户及其主目录、邮件 spool 和组信息。-D 或 --no-create-home:删除用户但不创建空的主目录(默认行为)。-s 或 --shell:指定用户的默认 shell。-Z 或 --selinux-user:删除用户的 SELinux 用户映射。删除用户及其主目录
deluser username -r
这将删除用户 username 及其主目录 /home/username。
强制删除用户账户
deluser username -f
即使用户 username 正在使用中,也会强制删除该账户。
删除用户及其主目录、邮件 spool 和组信息
deluser username -a
这将删除用户 username 及其主目录、邮件 spool 和组信息。
删除用户但不创建空的主目录
deluser username -D
这将删除用户 username,但不会创建空的主目录。
指定用户的默认 shell
deluser username -s /bin/bash
这将删除用户 username 并将其默认 shell 设置为 /bin/bash。
删除用户的 SELinux 用户映射
deluser username -Z
这将删除用户 username 的 SELinux 用户映射。
-f 选项强制删除。-g 选项单独处理。通过以上选项和示例,您可以灵活地使用 deluser 命令来管理 CentOS 系统中的用户账户。