---
title: "登录、令牌和认领错误 | Wantastic Docs"
description: "解决认领问题（genkey、二维码、Claim Device）、\"Login failed: …\" 消息和令牌错误。"
url: "https://wantastic.app/zh/docs/errors-login-claim"
category: "Troubleshooting"
reading_time: "6 分钟"
---

# 登录、令牌和认领错误

解决认领问题（genkey、二维码、Claim Device）、"Login failed: …" 消息和令牌错误。

> **Outcome:** genkey 输出 "Device claimed"（或 login 输出 "Login successful"），且重启服务后设备显示为 Online。

## Before you start

- Linux 和 macOS 上使用 sudo，OpenWrt 上使用 root shell。
- 设备时钟准确（误差在 30 秒以内）。

## 认领的工作原理

1. 运行 sudo wantasticd genkey。它会打印 Claim URL 和二维码，然后等待。
2. 打开 Claim URL 或扫描二维码，登录后点击 Claim Device。
3. 终端输出 "Device claimed"。按 Ctrl+C 并重启服务。

- 在 Linux 和 macOS 上始终使用 sudo。没有 sudo 时，配置会保存到服务无法读取的位置。
- 设备时钟必须准确。认领请求带有签名，服务器只接受 ±30 秒的误差。
- 在你点击 Claim Device 之前，出现 "Claim not ready yet" 是正常的。

Linux:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

## 检查要点

1. Claim Device 失败，或终端显示 401 时间戳错误：校正时钟，然后再次点击 Claim Device。
2. 已认领但仍为 Offline：使用 sudo 重新运行 genkey，然后重启服务。
3. 令牌被拒绝：跳过令牌，使用 genkey 认领（Windows：创建新的密钥）。
4. 设备数量上限：删除不用的设备或升级套餐。

*失败：设备时钟错误: 时钟与实际时间相差太大，认领被拒绝。*

```
$ $ date -u
Thu Jan  1 00:03:12 UTC 1970
Claim polling not ready: claim config rejected (401): invalid signature or timestamp out of window
```

*已修复：设置时钟，重新认领: 时钟正确后，在控制台中再次点击 Claim Device。*

```
$ $ sudo timedatectl set-ntp true
$ $ sudo wantasticd genkey
Reused existing device claim key: /etc/wantastic/device-claim-key.json
Waiting for claim. Press Ctrl+C to stop.
Device claimed. Configuration saved to /etc/wantastic/config.conf
```

*Console: Claim URL 打开此窗口时已自动填好信息。*

1. 公钥已填写
2. 保持显示的服务器不变
3. 点击 Claim Device

## 速查表

| 错误 | 最简单的修复方法 |
| --- | --- |
| claim config rejected (401): invalid signature or timestamp out of window | 校正时钟，再次点击 Claim Device。 |
| 已认领，但服务仍为 Offline | 使用 sudo 重新运行 genkey，然后重启。 |
| registration rejected (401): invalid or expired login token | 改用 genkey 认领，不使用令牌。 |
| account has reached its device limit — … | 删除一台设备或升级套餐。 |
| register endpoint returned 500 / 503 | 稍后重试。 |
| device code expired / authorization was denied by the user | 改用 genkey 认领。 |
| device code endpoint returned <code>: <body> | --portal-url 错误。 |
| x509: certificate … | 自托管：使用有效证书，或使用 --server。 |
| Failed to save configuration: write config file: … | 以 root 身份运行；释放空间。 |
| genkey failed: parse existing key file | genkey --force。 |

## Verify the result

- genkey 输出 "Device claimed. Configuration saved to /etc/wantastic/config.conf"（或 login 输出 "Login successful"）。
- 重启服务后，设备在 Devices 中显示为 Online。

## Common issues

### 打开 Claim URL 后，在控制台中点击 Claim Device 失败。

```
Claim polling not ready: claim config rejected (401): invalid signature or timestamp out of window
```

- **Where:** wantasticd genkey / connect --wait-claim
- **Likely cause:** 设备时钟与实际时间相差超过 30 秒。
- **Fix:** 设置时钟，然后再次点击 Claim Device。无需生成新密钥。

1. 运行适用于你系统的时钟命令。
2. 确认 date -u 显示当前的 UTC 时间。
3. 在控制台中再次点击 Claim Device。
4. 出现 "Device claimed" 后，按 Ctrl+C 并重启服务。

Shell:

```bash
sudo timedatectl set-ntp true   # Linux with systemd
ntpd -q -p pool.ntp.org         # OpenWrt and BusyBox
date -u
```

- **Verify:** genkey 输出 "Device claimed"。

### 终端显示 "Device claimed"，但按 Ctrl+C 后设备仍为 Offline。

- **Where:** wantasticd genkey（Linux 和 macOS）
- **Likely cause:** genkey 未使用 sudo 运行，因此配置保存在你的主目录中，而服务不会读取该位置。
- **Fix:** 使用 sudo 重新运行 genkey，重新认领，然后重启服务。

1. 运行 sudo wantasticd genkey。
2. 打开新的 Claim URL 并点击 Claim Device。
3. 确认保存路径是 /etc/wantastic/config.conf，而不是主目录中的路径。
4. 按 Ctrl+C 并重启服务。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** wantasticd status 显示 Connected。

### 已认领且为 Online，但按 Ctrl+C 后又变为 Offline。

- **Where:** wantasticd genkey
- **Likely cause:** genkey 在前台运行了隧道。Ctrl+C 停止了它，而服务没有重启。
- **Fix:** 重启一次服务。

Shell:

```bash
sudo systemctl restart wantasticd                 # Linux
sudo launchctl kickstart -k system/com.wantastic.wantasticd   # macOS
/etc/init.d/wantasticd restart                       # OpenWrt
```

- **Verify:** 设备在一分钟内于 Devices 中显示为 Online。

### 令牌登录被拒绝。

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

- **Where:** wantasticd login / install.sh
- **Likely cause:** 令牌错误、已过期或已用完。
- **Fix:** 跳过令牌，使用 genkey 认领设备。在 Windows 上，在 Account → Secrets 中创建新的密钥。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** 设备处于 Online 状态。

### 已达到套餐的设备数量上限。

```
Login failed: account has reached its device limit — upgrade your plan or remove an existing device
```

- **Where:** wantasticd login（控制台："You have reached the maximum number of devices for your plan."）
- **Likely cause:** 你的套餐没有空余的设备名额。
- **Fix:** 在 Devices 中删除不用的设备或升级套餐，然后重新认领。

- **Verify:** 认领或登录成功。

### 注册期间服务器出错。

```
Login failed: register endpoint returned 500
```

- **Where:** wantasticd login
- **Likely cause:** 临时性服务器错误。
- **Fix:** 几分钟后重试。如果问题持续，请发送邮件至 hello@wantastic.app，注明时间和设备名称。

- **Verify:** 重试后登录成功。

### 服务暂时不可用。

```
Login failed: register endpoint returned 503
```

- **Where:** wantasticd login
- **Likely cause:** 核心服务正在重启（自托管：core 容器尚未就绪）。
- **Fix:** 一分钟后重试。自托管：检查 docker logs -f wantastic。

- **Verify:** 登录成功。

### 设备码超时。

```
Login failed: device code expired — please start a new login
```

- **Where:** wantasticd login（设备码流程）
- **Likely cause:** 15 分钟内没有人批准该设备码。
- **Fix:** 改用 genkey 认领流程。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** genkey 输出 "Device claimed"。

### 设备码已过期（其他提示文字）。

```
device code expired — please try again
```

- **Where:** wantasticd login / 激活页面
- **Likely cause:** 没有人及时批准该设备码。
- **Fix:** 改用 genkey 认领流程。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** genkey 输出 "Device claimed"。

### 激活页面拒绝该设备码。

```
This code is invalid or has expired.
```

- **Where:** 控制台 · /activate
- **Likely cause:** 设备码有拼写错误或已过期。"This code has already been used." 表示该设备码此前已被批准。
- **Fix:** 改用 genkey 认领流程。如果提示 "You must be signed in to authorize a device."，请先点击 Sign In。

- **Verify:** genkey 输出 "Device claimed"。

### 登录被拒绝。

```
Login failed: authorization was denied by the user
```

- **Where:** wantasticd login
- **Likely cause:** 有人在激活页面上点击了 Deny。
- **Fix:** 使用 genkey 认领流程，并点击 Claim Device。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** genkey 输出 "Device claimed"。

### 登录错误。

```
Login failed: access denied: <desc>
```

- **Where:** wantasticd login
- **Likely cause:** 登录服务器拒绝了请求。"token error '<e>': <desc>" 和 "token endpoint returned <code> with no error field" 属于同一情况。
- **Fix:** 使用 genkey 认领流程。如果是自托管控制台，请检查控制台 URL 和服务器健康状况。

- **Verify:** 认领成功。

### 控制台 URL 错误。

```
Login failed: device code endpoint returned <code>: <body>
```

- **Where:** wantasticd login
- **Likely cause:** --portal-url 指向的不是 Wantastic 控制台。控制台启动期间可能显示 "Portal not ready (<code>): … retrying"。
- **Fix:** 移除 --portal-url 以使用默认值，或传入你自己的控制台 URL。

Shell:

```bash
sudo wantasticd genkey --server-url https://<your-console-host>
```

- **Verify:** 打印出包含你的控制台主机名的 Claim URL。

### 自托管证书错误。

```
x509: certificate signed by unknown authority
```

- **Where:** wantasticd login（自托管）
- **Likely cause:** 自托管控制台使用了自签名证书或不完整的证书。
- **Fix:** 安装有效证书（在设置向导中使用 Let's Encrypt），或使用会跳过证书检查的 --server。

Shell:

```bash
sudo wantasticd login --no-connect --server <your-console-host> --token <TOKEN>
```

- **Verify:** 登录成功。

### 配置路径错误。

```
Failed to prepare config path: parent <dir> is not a directory
```

- **Where:** wantasticd login
- **Likely cause:** 配置目录所在位置存在一个同名文件。
- **Fix:** 移走旧文件，然后重新认领。

Shell:

```bash
ls -l /etc/wantastic
sudo mv /etc/wantastic /etc/wantastic.old
sudo wantasticd genkey
```

- **Verify:** genkey 输出 "Device claimed. Configuration saved to …"。

### 无法保存配置。

```
Failed to save configuration: write config file: …
```

- **Where:** wantasticd login
- **Likely cause:** 你不是 root，或文件系统为只读或已满。
- **Fix:** 使用 sudo 运行，必要时释放空间。

Shell:

```bash
df -h /etc
sudo wantasticd genkey
```

- **Verify:** 配置已保存。

### 认领服务不可用。

```
claim config unavailable (503)
```

- **Where:** wantasticd genkey / connect --wait-claim
- **Likely cause:** 服务器暂时繁忙。
- **Fix:** 保持 genkey 运行，它每 10 秒重试一次。

- **Verify:** 认领完成。

### WebSocket 回退提示。

```
Claim websocket unavailable, falling back to signed polling
```

- **Where:** wantasticd 日志
- **Likely cause:** 代理或防火墙阻止了 WebSocket。轮询方式仍然可用。
- **Fix:** 无需操作。如果随后轮询返回 401 错误，请校正时钟。

- **Verify:** 认领完成。

### 等待认领。

```
Claim not ready yet
```

- **Where:** wantasticd 日志
- **Likely cause:** 这是正常现象，还没有人认领该设备。
- **Fix:** 打开 Claim URL 或扫描二维码，登录并点击 Claim Device。

- **Verify:** 控制台显示 "Wantastic device claimed"。

### 已找到认领，配置尚未就绪。

```
Claim found but config is not ready: …
```

- **Where:** wantasticd 日志
- **Likely cause:** 服务器仍在准备设备配置。
- **Fix:** 等待 20 秒。如果问题持续，在 Devices 中删除该设备并重新认领。

- **Verify:** 出现 "Device claimed"。

### genkey 无法读取旧密钥。

```
genkey failed: parse existing key file
```

- **Where:** wantasticd genkey
- **Likely cause:** 密钥文件已损坏。"existing key file missing private_key or public_key" 属于同一情况。
- **Fix:** 使用 --force 创建新密钥，然后通过新的 Claim URL 认领。

Shell:

```bash
sudo wantasticd genkey --force
```

- **Verify:** 打印出新的 Claim URL 和二维码。

### 找不到认领密钥文件。

```
Failed to load claim key: read key file: …
```

- **Where:** wantasticd connect --wait-claim
- **Likely cause:** 从未运行过 genkey，或 --claim-key 指向了错误的文件。
- **Fix:** 运行 genkey 并认领设备。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** genkey 输出 "Device claimed"。

### 服务器地址错误。

```
unsupported portal scheme for claim wait
```

- **Where:** wantasticd genkey / connect
- **Likely cause:** --server-url 不是以 https:// 开头。
- **Fix:** 传入完整的 https:// 地址。

Shell:

```bash
sudo wantasticd genkey --server-url https://console.wantastic.app
```

- **Verify:** 打印出 Claim URL。

## Continue with

- [Troubleshooting: start here](https://wantastic.app/zh/docs/troubleshooting): Fix most problems in 3 steps. If that does not work, find your exact error in the table and open the matching guide.
- [Enrollment secrets](https://wantastic.app/zh/docs/enrollment-secrets): Tokens for automation, Windows and mass rollouts: create, limit and delete them.
- [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.
- [wantasticd CLI reference and operations](https://wantastic.app/zh/docs/wantasticd): The most used wantasticd commands first, then every command and flag, environment variables, config and state paths per OS, log lines, local access, exit node, and the claim flow (genkey / --wait-claim).
- [Installer errors (install.sh and install.ps1)](https://wantastic.app/zh/docs/errors-installer): Every message the Wantastic installers print when they stop, what it means and the easiest fix.
- [Self-host WantasticCore](https://wantastic.app/zh/docs/self-hosting): Run your own Wantastic console with one command: install, setup wizard, DNS, ports, devices and backups.
