User Management
Managing users via the CLI with SQL backends
The trojan auth CLI provides user management for SQL authentication backends. This requires a SQL database (SQLite, PostgreSQL, or MySQL).
Initialize the Database
Create the database schema:
trojan auth init --database sqlite://users.dbSupported database URLs:
| Backend | URL Format |
|---|---|
| SQLite | sqlite://path/to/users.db |
| PostgreSQL | postgres://user:pass@host/dbname |
| MySQL | mysql://user:pass@host/dbname |
Add a User
trojan auth add --database sqlite://users.db \
--password "user-password" \
--upload-limit 10737418240 \
--download-limit 107374182400Options
| Option | Description |
|---|---|
--password | User password (required) |
--upload-limit | Upload traffic limit in bytes (0 = unlimited) |
--download-limit | Download traffic limit in bytes (0 = unlimited) |
--expire | Account expiration timestamp |
The password is hashed with SHA-224 and stored as a 56-byte hex string.
List Users
# Table format (default)
trojan auth list --database sqlite://users.db
# JSON format
trojan auth list --database sqlite://users.db --format json
# CSV format
trojan auth list --database sqlite://users.db --format csvOutput includes: password hash, upload/download traffic, limits, expiration, and enabled status.
Update a User
trojan auth update --database sqlite://users.db \
--password "user-password" \
--upload-limit 21474836480Remove a User
trojan auth remove --database sqlite://users.db \
--password "user-password"Reset Traffic Counters
trojan auth reset-traffic --database sqlite://users.db \
--password "user-password"Resets both upload and download byte counters to zero.
Traffic Limits
Traffic limits are specified in bytes. Common values:
| Size | Bytes |
|---|---|
| 1 GB | 1073741824 |
| 10 GB | 10737418240 |
| 100 GB | 107374182400 |
| 1 TB | 1099511627776 |
| Unlimited | 0 |
When a user exceeds their traffic limit, authentication is rejected until the counters are reset or the limits are increased.