---
title: "注册密钥 | Wantastic Docs"
description: "用于自动化、Windows 和批量部署的令牌：创建、限制和删除。"
url: "https://wantastic.app/zh/docs/enrollment-secrets"
category: "Start here"
reading_time: "4 分钟"
---

# 注册密钥

用于自动化、Windows 和批量部署的令牌：创建、限制和删除。

> **Outcome:** 每次部署都有自己的短期令牌，泄露的令牌可以直接删除，不会影响已连接的设备。

## Before you start

- 可访问 Account → Secrets

## 你需要密钥吗？

- 通常不需要。对于单台 Linux、Mac 或 OpenWrt 设备，认领方式更简单（参见“快速入门”）。
- Windows 需要密钥，因为 Windows 不会显示认领二维码。
- 批量部署、脚本或设备镜像需要密钥。
- 没有屏幕、也没有人扫描二维码的设备需要密钥。

## 创建密钥

1. 打开 Account → Secrets，点击 + New Secret。
2. Secret Name：写明用途，例如 "Tower 12 install"。
3. Expiry (Days, 0 for never) 和 Max Uses (0 for unlimited)：两者都尽量设小。
4. 点击 Generate 并复制令牌。

*Console: Account → Secrets。*

1. 点击 + New Secret
2. 为其命名
3. 多少天后过期
4. 可用于多少台设备
5. 点击 Generate
6. 复制令牌

> **Tip:** 外勤施工时，将 Expiry 设为 1，Max Uses 设为设备数量。

## 使用令牌

### Linux / macOS

使用令牌安装:

```sh
curl -fsSL https://get.wantastic.app/install.sh | sudo sh -s -- --token <TOKEN>
```

### OpenWrt / Alpine

以 root 身份登录。

使用令牌安装:

```sh
wget -qO- https://get.wantastic.app/install.sh | sh -s -- --token <TOKEN>
```

### Windows

以管理员身份打开 PowerShell。

使用令牌安装:

```powershell
& ([scriptblock]::Create((irm https://get.wantastic.app/install.ps1))) -Token <TOKEN>
```

### 已安装

使用令牌登录:

```sh
sudo wantasticd login --no-connect --token <TOKEN>
sudo systemctl restart wantasticd
```

> **Operational note:** 列表下方的 Show Enrollment Script 会为你生成命令。请检查命令中是否带有 sudo，且令牌前面有 --token。

## 密钥用尽时

- 达到 Expiry 或 Max Uses 后，新设备将无法再使用该密钥。
- 已加入的设备会继续正常工作。密钥只控制新设备。
- 密钥行上的 Usage 显示有多少台设备使用了它。

## 删除或替换密钥

1. 先创建新密钥，并更新你的脚本。
2. 在 Account → Secrets 中删除旧密钥。
3. 如果密钥已泄露，请立即删除，并在 Devices 中检查是否有你不认识的设备。

> **Warning:** 密钥相当于向你账户添加设备的密码。不要把它粘贴到工单、聊天或录屏中。

## Verify the result

- 新密钥显示在 Account → Secrets 中。
- 每有一台设备加入，Usage 加一。
- 已删除的密钥会被拒绝，并提示 "invalid or expired login token"。

## Common issues

### 设备提示令牌无效。

```
Login failed: registration rejected (401): invalid or expired login token
```

- **Where:** install.sh / wantasticd login
- **Likely cause:** 令牌错误、已过期，或已达到 Max Uses。
- **Fix:** 创建新密钥并重新登录。在 Linux、Mac 或 OpenWrt 上，也可以改用认领方式。

改用认领（Linux、Mac）:

```sh
sudo wantasticd genkey
```

### 安装程序已完成，但没有登录。

```
Skipping login. Run 'wantasticd login' to authenticate.
```

- **Where:** install.sh
- **Likely cause:** 传入令牌时前面没有加 --token。
- **Fix:** 使用 --token 登录，然后重启服务。

修复:

```sh
sudo wantasticd login --no-connect --token <TOKEN>
sudo systemctl restart wantasticd
```

### 创建密钥失败。

```
Secret name is required
```

- **Where:** Account → Secrets
- **Likely cause:** Secret Name 为空。
- **Fix:** 输入名称，然后再次点击 Generate。

## Continue with

- [Device onboarding](https://wantastic.app/zh/docs/device-onboarding): The easiest way to connect each kind of device: claim for Linux, Mac and OpenWrt, a script for MikroTik, a QR code for phones, and tokens for automation.
- [Getting started](https://wantastic.app/zh/docs/getting-started): Sign up, connect your first device and open Winbox or a browser SSH terminal on it. About five minutes.
- [Security model](https://wantastic.app/zh/docs/security-model): What Wantastic opens on your devices, how access is limited, and how to remove access fast.
- [Choose your install method](https://wantastic.app/zh/docs/install-overview): Find your device in one table and copy one command. Most devices install in 2 minutes: install, scan a QR code, click Claim Device.
- [Login, token and claim errors](https://wantastic.app/zh/docs/errors-login-claim): Fix claim problems (genkey, QR code, Claim Device), "Login failed: …" messages and token errors.
