> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/yong-hu-he-xiang-mu-guan-li/user-management.md).

# 用户管理

## 创建管理员用户

Overleaf Toolkit 部署：

{% code title="Overleaf Toolkit" overflow="wrap" %}

```bash
$ bin/docker-compose exec sharelatex /bin/bash -ce "cd /overleaf/services/web && node modules/server-ce-scripts/scripts/create-user --admin --email=joe@example.com"
```

{% endcode %}

旧版 docker-compose.yml 部署：

{% code title="旧版 docker-compose" overflow="wrap" %}

```bash
$ docker exec sharelatex /bin/bash -ce "cd /overleaf/services/web && node modules/server-ce-scripts/scripts/create-user --admin --email=joe@example.com"
```

{% endcode %}

该命令会使用提供的电子邮件地址创建一个用户（如果该用户尚不存在），并将其设为管理员。命令输出中会包含一个可访问的 URL，您可以在其中为该用户设置密码并首次登录。

{% hint style="info" %}
如果你希望通过程序化方式操作，也可以使用同一个脚本创建普通用户以及管理员。创建普通用户时省略 --admin 标志。
{% endhint %}

如果你使用内部账户进行身份验证，并且需要将现有用户提升为实例管理员或撤销管理员权限，请按以下步骤操作：

{% stepper %}
{% step %}

### 通过管理界面

* 以现有管理员身份登录。
* 点击 Admin -> Manage Users。
* 搜索该用户并点击其电子邮件地址。
* 向下滚动到 Site Admin 部分并点击（显示）链接。
* 勾选 Is Site Admin 复选框。
* 点击 Save 完成。
  {% endstep %}
  {% endstepper %}

***

## 删除用户

如我们关于以下内容的指南中所解释的 [理解许可证使用情况](broken://pages/d230224dd1d2315ee9c2326f6100d5688c8f2e3c)，通常不建议删除账户，除非它们已不再需要。删除账户会移除该账户，并导致协作者失去对项目的访问权限。目前没有办法停用账户——它们要么存在且数据保留，要么被删除。

默认情况下，账户采用软删除。有关从实例中永久移除用户的信息，请参见 `ENABLE_CRON_RESOURCE_DELETION` 设置在 [环境变量](broken://pages/8e0a2795a807f6db8f317f47523c2b84136db8ed) 指南。

{% hint style="info" %}
账户默认采用软删除。请参见 `ENABLE_CRON_RESOURCE_DELETION` 了解永久删除行为。
{% endhint %}

### 通过 Admin -> Manage Users

{% stepper %}
{% step %}

* 以管理员身份登录。
* 点击 Admin -> Manage Users。
* 搜索该用户并勾选其电子邮件地址旁边的复选框。
* 点击垃圾桶图标。
* 点击 Delete 以确认。
  {% endstep %}
  {% endstepper %}

### 通过命令行

可以使用以下命令删除用户账户（及其项目）。

Overleaf Toolkit 部署：

{% code title="Overleaf Toolkit" %}

```bash
$ bin/docker-compose exec sharelatex /bin/bash -ce "cd /overleaf/services/web && node modules/server-ce-scripts/scripts/delete-user.mjs --email=joe@example.com"
```

{% endcode %}

旧版 docker-compose.yml 部署：

{% code title="旧版 docker-compose" %}

```bash
$ docker exec sharelatex /bin/bash -ce "cd /overleaf/services/web && node modules/server-ce-scripts/scripts/delete-user.mjs --email=joe@example.com"
```

{% endcode %}

{% hint style="danger" %}
删除脚本使用了硬编码的 force 选项，以确保即使账户删除邮件发送失败（例如用户的电子邮件已停用），删除仍会继续执行。
{% endhint %}

{% hint style="info" %}
从 5.5.0 版本开始，可以使用 --skip-email 选项来阻止向已删除用户发送通知邮件。
{% endhint %}

***

## 恢复已软删除的用户

如果用户只是被软删除，你可以恢复其账户和项目。

{% stepper %}
{% step %}

* 以管理员身份登录。
* 点击 Admin -> Manage Users。
* 搜索你要恢复的用户。
* 点击 Display deleted users 按钮。
* 点击已删除用户的电子邮件地址。
* 点击 Recover This Account。
* 点击 Recover 以确认。
  {% endstep %}
  {% endstepper %}

{% hint style="danger" %}
当 ENABLE\_CRON\_RESOURCE\_DELETION 设置为 true 时，软删除的账户可在 90 天内恢复。超过 90 天后，将无法恢复账户。
{% endhint %}

***

## 统计用户数

你可以通过管理界面 <https://you-instance-url/admin/user#license> 获取用户数量。对于程序化检查和导出，以下示例可能会有所帮助。

用户总数：

{% code title="用户总数" %}

```bash
echo 'db.users.countDocuments()' | docker exec -i mongo mongosh --quiet localhost/sharelatex
# overleaf [direct: primary] sharelatex> 16
```

{% endcode %}

通过 metrics 端点获取的用户总数：

{% code title="metrics 中的活跃用户数" %}

```bash
docker exec sharelatex curl http://127.0.0.1:3000/metrics | grep num_active_users
# # HELP num_active_users num_active_users
# # TYPE num_active_users gauge
# num_active_users{app="web-api",host="b3ae4ff549d8"} 16
```

{% endcode %}

活跃用户总数（例如：过去 365 天内活跃的用户）：

{% code title="活跃用户总数" %}

```bash
echo 'db.users.countDocuments({ lastActive: { $gte: new Date(new Date().getTime() - (365 * 24 * 60 * 60 * 1000)) } })' | docker exec -i mongo mongosh --quiet localhost/sharelatex
# overleaf [direct: primary] sharelatex> 10
```

{% endcode %}

***

## 更新用户账户信息

账户更新的执行方式取决于是否启用了 SSO。

* 如果未使用 SSO：
  * 管理员可以通过 Admin -> Manage Users 修改用户账户信息（电子邮件、名字、姓氏，并生成密码重置链接）。
  * 普通用户可以通过 Account -> Account Settings 更新自己的信息（包括更改密码以及生成 Git 认证令牌）。
* 如果使用了 SSO：
  * 可以将 Server Pro 配置为在登录时根据身份验证系统更新用户的名字和姓氏。
  * 当 OVERLEAF\_SAML\_UPDATE\_USER\_DETAILS\_ON\_LOGIN 或 OVERLEAF\_LDAP\_UPDATE\_USER\_DETAILS\_ON\_LOGIN 为 true 时，<https://your-instance-url/user/settings> 上的用户详情表单将被禁用，名字/姓氏只能在你的身份管理系统中设置。

更多详情请参见：

* SAML 2.0 配置：<https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/server-pro-only-configuration/saml-2.0>
* LDAP 配置：<https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/server-pro-only-configuration/ldap>

***

上次更新于 4 个月前

此文档页面包含指向外部指南和配置页面的链接。所有链接和查询参数都将按原始内容保留。


---

# 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://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/yong-hu-he-xiang-mu-guan-li/user-management.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.
