> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man8/rmuser.8.md).

# rmuser.8

`rmuser` — 从系统中删除用户

## 名称

`rmuser`

## 概要

`rmuser [-yv] [-f file] [username ...]`

## 描述

`rmuser` 工具用于删除命令行上或文件中提交的一个或多个用户。从系统中删除用户时，该工具会：

* 删除用户的 crontab(1) 条目（如果有）。
* 删除属于该用户的任何 [at(1)](/man/man1/at.1.md) 作业。
* 向该用户拥有的所有进程发送 `SIGKILL` 信号。
* 从系统的本地密码文件中删除该用户。
* 删除用户的主目录（如果该目录归用户所有），包括处理指向实际主目录路径中的符号链接。
* 从 **/var/mail** 中删除属于该用户的收件箱和 POP 守护进程邮件文件。
* 从 **/tmp**、**/var/tmp** 和 **/var/tmp/vi.recover** 中删除该用户拥有的所有文件。
* 从 **/etc/group** 中该用户所属的所有组中删除其用户名。（如果某个组变空且组名与用户名相同，则该组会被删除；这与 [adduser(8)](/man/man8/adduser.8.md) 的每用户唯一组机制互补。）
* 删除该用户拥有的所有消息队列、共享内存段和信号量。

`rmuser` 工具拒绝删除 UID 为 0 的用户（通常是 root），因为某些操作（即杀死该用户的所有进程，以及可能删除用户主目录）会对正在运行的系统造成损害。如果需要删除 UID 为 0 的用户，请参见 vipw(8) 了解直接编辑密码文件的信息。

如果调用 `rmuser` 时未指定 `-y` 选项，它会显示所选用户的密码文件条目并要求确认是否删除该用户。然后会要求确认是否删除该用户的主目录。如果回答为肯定，则仅当主目录及其下的所有文件和子目录归该用户所有时才会删除它们。更多细节请参见 [pw(8)](/man/man8/pw.8.md)。

`rmuser` 在执行过程中会向用户报告当前活动。如果发生任何错误，会输出到标准错误，并且只要 `rmuser` 能够继续，它就会继续执行。

选项如下：

**`-f`** `file` `rmuser` 工具将从 `file` 中获取要删除的用户列表，该文件每行包含一个用户名。井号（`#`）后面的任何内容，包括井号本身，都被视为注释而不予处理。如果该文件的所有者不是 UID 为 0 的用户，或者该文件可被所有者以外的其他人写入，`rmuser` 将拒绝继续。

**`-y`** 对所有提示隐式回答“`yes`”。目前，这包括是否删除指定用户以及是否删除主目录的提示。此选项要求使用 `-f` 选项，或在命令行上给出一个或多个用户名作为参数。

**`-v`** 启用详细模式。通常，输出中每个被删除的用户占一行；但使用此选项时，`rmuser` 会更详细地报告所执行的步骤。

**`username`** 指定要删除的一个或多个用户；如果未指定，`rmuser` 会交互式地询问要删除的一个或多个用户。

## 文件

**/etc/master.passwd** **/etc/passwd** **/etc/group** **/etc/spwd.db** **/etc/pwd.db**

## 参见

[at(1)](/man/man1/at.1.md), chpass(1), crontab(1), finger(1), [passwd(1)](/man/man1/passwd.1.md), [group(5)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man5/group.5.md), [passwd(5)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man5/passwd.5.md), [adduser(8)](/man/man8/adduser.8.md), [pw(8)](/man/man8/pw.8.md), pwd\_mkdb(8), vipw(8)

## 历史

`rmuser` 工具出现于 FreeBSD 2.2。

## 缺陷

`rmuser` 工具不会全面搜索文件系统以查找并删除被删除用户拥有的所有文件；在任何规模较大的系统上这样做都极其缓慢且 I/O 密集。它也无法删除用户在 **/tmp** 或 **/var/tmp** 中创建的符号链接，因为 4.4BSD 文件系统上的符号链接不包含有关创建者身份的信息。此外，在 **/var/mail** 中可能存在除 **/var/mail/username** 和 **/var/mail/.pop.username** 之外的其他文件，它们虽然不归被删除用户所有，但也应被删除。

`rmuser` 工具不了解 YP/NIS，它仅在本地密码文件上操作。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man8/rmuser.8.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
