Pubky CLI
Pubky CLI is a command-line tool for interacting with Pubky Homeservers. Built in Rust, it provides both user-facing and administrative capabilities for managing Homeservers, testing deployments, and automating workflows.
Overview
Section titled “Overview”Pubky CLI wraps the official Pubky SDK and provides:
- User Operations: Signup, signin, data management, session handling
- Admin Operations: User management, server stats, invite token generation
- Testing Tools: Integration with
pubky-testnetfor local development - Automation: Script-friendly interface for CI/CD and deployment automation
Installation
Section titled “Installation”From Crates.io
Section titled “From Crates.io”cargo install pubky-cliFrom Source
Section titled “From Source”git clone https://github.com/pubky/pubky-clicd pubky-clicargo install --path .Verify Installation
Section titled “Verify Installation”pubky-cli --versionQuick Start
Section titled “Quick Start”Create Recovery File
Section titled “Create Recovery File”Recovery files store encrypted identity keys:
# Generate recovery file with passphrasepubky-cli tools generate-recovery ./alice.recovery --passphrase mypass
# Prints the public key# Example: z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdftyUser Signup
Section titled “User Signup”# Sign up with homeserver (testnet)PUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user signup <homeserver-pubkey> ./alice.recovery --testnet
# With signup code (for gated servers)PUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user signup --signup-code <code> <homeserver-pubkey> ./alice.recovery --testnetAdmin Operations
Section titled “Admin Operations”# Get server infoPUBKY_ADMIN_PASSWORD=admin \ pubky-cli admin info
# Generate signup tokenPUBKY_ADMIN_PASSWORD=admin \ pubky-cli admin generate-tokenUser Commands
Section titled “User Commands”Authentication
Section titled “Authentication”# Sign inPUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user signin ./alice.recovery --testnet
# Check sessionPUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user session ./alice.recovery --testnet
# Sign outPUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user signout ./alice.recovery --testnetData Management
Section titled “Data Management”# Publish data from filePUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user publish "/pub/myapp/data.json" ./local-file.json ./alice.recovery --testnet
# Get data by pathPUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user get "/pub/myapp/data.json" ./alice.recovery --testnet
# List directoryPUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user list "/pub/myapp/" ./alice.recovery --testnet
# Delete dataPUBKY_CLI_RECOVERY_PASSPHRASE=mypass \ pubky-cli user delete "/pub/myapp/data.json" ./alice.recovery --testnetAdmin Commands
Section titled “Admin Commands”User Management
Section titled “User Management”# Disable userPUBKY_ADMIN_PASSWORD=admin \ pubky-cli admin user disable <user-pubkey>
# Enable userPUBKY_ADMIN_PASSWORD=admin \ pubky-cli admin user enable <user-pubkey>
# Delete user dataPUBKY_ADMIN_PASSWORD=admin \ pubky-cli admin user delete <user-pubkey> /path/to/fileServer Operations
Section titled “Server Operations”# Get server statisticsPUBKY_ADMIN_PASSWORD=admin \ pubky-cli admin info
# Generate invite/signup tokenPUBKY_ADMIN_PASSWORD=admin \ pubky-cli admin generate-tokenEnvironment Variables
Section titled “Environment Variables”| Variable | Purpose | Example |
|---|---|---|
PUBKY_ADMIN_PASSWORD | Admin API password | admin |
PUBKY_CLI_RECOVERY_PASSPHRASE | Auto-decrypt recovery files | mypassphrase |
PUBKY_PKARR_BOOTSTRAP | Override PKARR bootstrap nodes | node1.example.com:6881,node2.example.com:6881 |
PUBKY_PKARR_RELAYS | Custom PKARR relay URLs | https://relay1.example.com,https://relay2.example.com |
PUBKY_PKARR_TIMEOUT_MS | PKARR request timeout | 5000 |
Shell Completions
Section titled “Shell Completions”Generate tab completion scripts for your shell:
# Bashpubky-cli tools completions bash --outfile "$(brew --prefix)/etc/bash_completion.d/pubky-cli"
# Zshmkdir -p ~/.zfuncpubky-cli tools completions zsh --outfile ~/.zfunc/_pubky-cliecho 'fpath+=("$HOME/.zfunc")' >> ~/.zshrc
# Fishpubky-cli tools completions fish --outfile ~/.config/fish/completions/pubky-cli.fish
# PowerShellpubky-cli tools completions powershell --outfile $PROFILE/../Completions/pubky-cli.ps1Supported shells: bash, zsh, fish, powershell, elvish
Testing & CI
Section titled “Testing & CI”Local Testing
Section titled “Local Testing”# Run all tests (includes integration tests)cargo test
# Test uses pubky-testnet internally - no external setup neededExample Workflow
Section titled “Example Workflow”#!/bin/bash# Automated user onboarding script
# 1. Generate recovery filepubky-cli tools generate-recovery ./user.recovery --passphrase $PASSWORD
# 2. Sign upPUBKY_CLI_RECOVERY_PASSPHRASE=$PASSWORD \ pubky-cli user signup $HOMESERVER_PK ./user.recovery --testnet
# 3. Sign inPUBKY_CLI_RECOVERY_PASSPHRASE=$PASSWORD \ pubky-cli user signin ./user.recovery --testnet
# 4. Publish initial profilePUBKY_CLI_RECOVERY_PASSPHRASE=$PASSWORD \ pubky-cli user publish "/pub/pubky.app/profile.json" ./profile.json ./user.recovery --testnet
echo "User onboarded successfully!"Use Cases
Section titled “Use Cases”Local Development
Section titled “Local Development”Test Homeserver functionality without building custom clients:
# Start local homeservercargo run -p pubky-homeserver -- --data-dir ~/.pubky
# Test with CLIpubky-cli admin infoDeployment Automation
Section titled “Deployment Automation”Script Homeserver configuration and user provisioning:
# Generate batch signup tokensfor i in {1..100}; do PUBKY_ADMIN_PASSWORD=$ADMIN_PASS pubky-cli admin generate-token >> tokens.txtdoneIntegration Testing
Section titled “Integration Testing”Validate end-to-end flows in CI:
# CI test scriptcargo test --allHomeserver Administration
Section titled “Homeserver Administration”Manage users and monitor server health:
# Disable abusive userPUBKY_ADMIN_PASSWORD=admin pubky-cli admin user disable $ABUSER_KEY
# Check server statsPUBKY_ADMIN_PASSWORD=admin pubky-cli admin infoArchitecture
Section titled “Architecture”Project Structure
Section titled “Project Structure”pubky-cli/├── src/│ ├── admin.rs # Admin API wrapper│ ├── user.rs # User operations (via Pubky SDK)│ ├── tools.rs # Utilities (recovery, completions)│ ├── util.rs # Shared helpers│ └── main.rs # CLI entry point├── tests/│ └── integration.rs # E2E tests with pubky-testnet└── Cargo.tomlDependencies
Section titled “Dependencies”- pubky SDK (
0.6.0-rc.6): User-facing operations - pubky-testnet: Local testing harness
- clap: Command-line argument parsing
- tokio: Async runtime
Troubleshooting
Section titled “Troubleshooting”Connection Issues
Section titled “Connection Issues”# Verify homeserver is runningcurl http://127.0.0.1:6287/
# Check admin APIcurl http://127.0.0.1:6288/Recovery File Errors
Section titled “Recovery File Errors”# Ensure passphrase is correctPUBKY_CLI_RECOVERY_PASSPHRASE=wrong-pass pubky-cli user signin ./alice.recovery# Error: Failed to decrypt recovery file
# Use correct passphrasePUBKY_CLI_RECOVERY_PASSPHRASE=correct-pass pubky-cli user signin ./alice.recovery# SuccessTestnet vs Production
Section titled “Testnet vs Production”# Testnet (local development)pubky-cli user signup $HOMESERVER_PK ./recovery --testnet
# Production (requires full homeserver URL)pubky-cli user signup $HOMESERVER_PK ./recovery- Crates.io: crates.io/crates/pubky-cli
- Repository: github.com/pubky/pubky-cli
- CI Status: GitHub Actions
- Pubky SDK: docs.rs/pubky
Related Documentation
Section titled “Related Documentation”- Pubky SDK - Client libraries for all platforms
- Pubky Homeservers - Homeserver deployment and configuration
- Pubky Docker - Full stack Docker environment
- Pubky Core API - HTTP API specification