pinggy
v0.7.0
Published
Create secure, shareable tunnels to your localhost and manage them from the command line.
Readme
Pinggy CLI
Create secure, shareable tunnels to your localhost and manage them from the command line.
Key features
- HTTP, TCP, UDP, TLS, TLSTCP tunnels to localhost
- SSH-style and user-friendly flags
- Web debugger for HTTP tunnels
- Extended options for auth, header manipulation, IP allowlists, CORS handling, etc.
- Persistent background daemon owns every tunnel; CLI invocations are short-lived
- Foreground (live TUI) and detached (
-b) tunnel modes - Lifecycle commands:
ps,start,stop,restart,attach - Per-tunnel and per-daemon log files with
pinggy logs(tail, follow, rotation-safe) - Device autostart with
pinggy autostart on(systemd, launchd, Task Scheduler) - Remote management via secure WebSocket connection (works with Pinggy Dashboard)
- Pinggy Devices: enrol the machine with
pinggy deviceand keep it visible in the dashboard - Save and load configuration files
- Config store for saving, listing, updating, and starting named tunnel configs
- Auto-start support for launching saved tunnels automatically
- Simple file server mode for quickly sharing local files
- Built-in TUI (Text User Interface) for viewing tunnel statistics, requests, and responses in real time
Architecture at a glance
The CLI runs as two processes. A short-lived foreground process is what you invoke. A long-running daemon owns every tunnel and the @pinggy/pinggy SDK. They talk over HTTP and WebSocket on 127.0.0.1.
See docs/ARCHITECTURE.md for the full breakdown of the two-process model, IPC routes, daemon discovery, session ownership, and filesystem layout.
Requirements
- Node.js 18+ (recommended). The CLI uses modern ESM and WebSocket features.
- A network connection that allows outgoing WebSocket/HTTPS traffic.
Installation
Global install is recommended for system-wide "pinggy" command.
- Using npm:
npm install -g pinggyAfter install, verify:
pinggy --helpQuick start
- Start a basic HTTP tunnel to localhost:3000:
pinggy -R0:localhost:3000- Start a TCP tunnel (e.g., SSH on port 22):
pinggy -R0:localhost:8000 [email protected]- Start HTTP tunnel with web debugger on 4300:
pinggy -R0:localhost:8000 -L4300:localhost:4300- Use a token and region/domain-like arg: pinggy [email protected] -p 3000. For more info read docs
The CLI prints generated public URLs (HTTP/HTTPS or TCP) and keeps the TUI attached until you press Ctrl+C. Tunnels run inside a background daemon. See Daemon and Running tunnels for ps, stop, and detached (-b) mode.
Config management
The CLI includes a built-in config store for saving, listing, and starting tunnel configurations. Configs are persisted as JSON files under the platform config directory (see State and file locations).
Configs can be looked up by name (exact match) or by configId prefix (partial match) in every config and start/stop/restart/attach subcommand.
Save a tunnel config
pinggy config save my-tunnel -l 3000 [email protected]Save with auto-start enabled
pinggy config save my-tunnel --auto -l 3000List all saved configs
pinggy config list
pinggy config ls # alias for listView details of a saved config
pinggy config show my-tunnel
pinggy config show my-tunnel other-tunnel # View multiple configs
pinggy config my-tunnel # Shorthand: same as `config show`Update a saved config
pinggy config update my-tunnel -l 4000Enable or disable auto-start
pinggy config auto my-tunnel
pinggy config noauto my-tunnel
pinggy config auto tunnel1 tunnel2 # Multiple configs at onceDelete a saved config
pinggy config delete my-tunnel
pinggy config delete tunnel1 tunnel2 # Delete multipleRunning tunnels
Every tunnel runs inside the daemon. The CLI either holds a live TUI subscription to it (foreground) or starts it and exits (detached).
Foreground vs detached
- Foreground (default):
pinggy start <name>. The CLI keeps a WebSocket open to the tunnel and renders the TUI. Use ctrl+C to close the TUI and stop the tunnel. - Detached (
-b):pinggy start -b <name>. The CLI prints the public URL, then exits. The tunnel persists in the daemon until you stop it explicitly withpinggy stop.
Start a saved tunnel
pinggy start my-tunnel # foreground, TUI attached
pinggy start -b my-tunnel # detached, CLI exits immediatelyStart with runtime overrides
pinggy start my-tunnel -l 4000Start multiple tunnels
pinggy start tunnel1 tunnel2Runtime overrides (
-l,--type,--token, ...) only apply when starting a single tunnel. For multiple tunnels, update the saved config first withpinggy config update.
Start all auto-start tunnels
pinggy start --allRuns through the daemon as detached tunnels. Useful for scripting and service startup.
Start with remote management
pinggy start --all --remote-management <API_KEY>
pinggy start tunnel1 tunnel2 --remote-management <API_KEY>Start with logging enabled
pinggy start my-tunnel --vvv
pinggy start --all --logfile /tmp/pinggy.log --loglevel DEBUGList running tunnels
pinggy psPrints a table of ID, name, status, local endpoint, and public URL.
Stop tunnels
pinggy stop my-tunnel
pinggy stop my-tunnel other-tunnel # multiple
pinggy stop abc12345 # by configId prefixRestart a tunnel
pinggy restart my-tunnelPreserves the existing mode (foreground stays foreground, detached stays detached).
Re-attach the TUI to a running tunnel
pinggy attach my-tunnelOpens a fresh TUI session against a tunnel that is already running. Useful to inspect a detached tunnel live.
Daemon
The daemon is the long-running process that owns every tunnel. The CLI starts it automatically when needed, so most users never call these commands directly. They exist for explicit control, scripting, and boot-time service install.
Both pinggy daemon and the alias pinggy d work.
Start the daemon
pinggy daemon startLists which configs will auto-start (any tagged with config auto).
Stop the daemon
pinggy daemon stopStops every running tunnel and shuts the daemon down cleanly.
Show daemon status
pinggy daemon statusPrints PID, port, start time, and uptime.
Remote management
You can control tunnels remotely using a secure WebSocket connection.
- Start remote management with a token:
pinggy --remote-management <API KEY>- Specify a management server (default is wss://dashboard.pinggy.io):
pinggy --remote-management <API KEY> --manage wss://custom.example.comPinggy Devices
Enrol this machine as a Pinggy device. The agent opens 1 WebSocket to the dashboard, registers the machine, and holds the connection open so the dashboard can show the device as online.
Devices and remote management are separate features. Remote management drives tunnels from the dashboard with an API key. A device is the machine itself, enrolled with its own token. The device agent owns no tunnels, and stopping it leaves every running tunnel alone.
The agent runs in the background, in the daemon, so it stays connected after the terminal closes. Once the daemon starts it, the CLI prints the commands that manage it: pinggy device status, stop, connect and remove. Add --foreground to keep the agent in this terminal until Ctrl+C. -b still works and changes nothing.
Sign in with your email
pinggy device loginThe CLI asks for your email and prints a Device Code. The dashboard emails a 6-digit code and an approve button. Type the code, or click the button. The approve page shows the same Device Code: approve only if it matches. The install script runs this command.
Connect a device
pinggy device connect --token <TOKEN>Add the device in the dashboard first, then pass the token it gives you. The CLI exits once the device connects, and the daemon reconnects it on its own until pinggy device stop.
The token is written to disk on the first successful connect, so later runs need no flag:
pinggy device connectpinggy device start is the same command. It takes the same flags.
Point the agent at a different dashboard with --manage:
pinggy device connect --token <TOKEN> --manage dashboard.pinggy.io--manage takes a host. The scheme becomes wss:// unless you type ws:// or wss:// yourself. The agent connects to /backend/api/v1/device-agent/ws/connect on that host and sends the token in the X-Pinggy-Device-Token header.
--token here is the device token, not the tunnel token of the same flag name in Options. The 2 credentials are unrelated and the device agent never reads the tunnel one.
Allow or refuse file access
The first pinggy device connect, start or login in a terminal asks "Allow file access from the Pinggy dashboard? Your account can browse, copy, move and delete this machine's files from the browser. [Y/n]". Enter allows it. The answer is saved, so later runs do not ask. With no terminal, nothing is asked and file access stays on.
Change the answer at any time. A running agent applies it to the next file request:
pinggy device connect --files off
pinggy device connect --files onWhile file access is off, the dashboard's file manager shows "File access is off on this device." pinggy device status prints the answer on its Files line. The browser terminal does not read this answer.
Show the device and whether it runs
pinggy device statusThe first line is the device's state:
| State | Meaning |
|-------|---------|
| running, connected | The agent runs in the daemon and the dashboard shows the device online |
| running, connecting or running, reconnecting | The agent runs in the daemon and is dialling the dashboard |
| running, with --foreground in another terminal | Another terminal runs pinggy device connect --foreground |
| stopped | No agent runs. pinggy device start or pinggy device connect starts it |
| unknown | A daemon runs but does not answer, for example after an update. pinggy daemon stop fixes it, and stops all running tunnels |
Then it prints the device id, server, masked token, and enrolment time from the local file. It asks the running daemon about its agent and never starts one. It contacts no server.
Forget the local credential
pinggy device removePrints the device id and whether the device is connected now, in the background or with --foreground in another terminal, then asks "Remove this device from this machine? [y/N]". Only y removes it: the command stops the device agent, then deletes the local credential. With no terminal, it refuses unless you add -f, which removes without asking. The device still exists in the dashboard. Delete it there to revoke it, because a machine that has lost its credential cannot authenticate the delete. When autostart is on, remove turns it off too.
Start on boot
pinggy autostart on # Bring this device online each time this computer starts
pinggy autostart off # Stop that. The device stays online until the next restart
pinggy autostart status # Show whether it is on. `pinggy autostart` alone does the sameon writes a boot entry that starts the daemon: a systemd user service on Linux, a launchd agent on macOS, a Task Scheduler task on Windows. On Linux it also turns on lingering, so the device comes online at boot with nobody signed in. On macOS and Windows it comes online when you sign in. Only the copy the Pinggy installer put in place may write the entry, so the npm version and a downloaded binary are refused with the command to run instead.
A restart brings the device back only when the daemon also runs its agent, which login, connect and start set up and --foreground does not. So on checks that first. With no background agent, it asks "Start it now, and each time this computer starts? [Y/n]" before it starts one. With no terminal it asks nothing and names pinggy device start. On a machine that is not signed in, it refuses and names pinggy device login.
off removes the boot entry and stops nothing, so it is safe to run from the dashboard's browser terminal. To take the device offline now, run pinggy device stop.
pinggy daemon service-install and pinggy daemon service-uninstall were the old names. They now print the new command and exit 1.
Reconnect and stop conditions
The agent retries a dropped connection every 5 seconds. Some failures are terminal and it exits instead:
| Event | Agent | |-------|-------| | HTTP 401 on the upgrade | Stops. The token is wrong or revoked. Re-enrol from the dashboard | | Dashboard refuses the handshake | Stops, and prints the reason | | Device is connected from another machine | Retries. The credential is fine, the other socket has to drop first | | Dashboard says it is shutting down | Retries | | Any other close, or a network error | Retries |
Ctrl+C stops the retry loop. The agent exits once the current socket closes; a second Ctrl+C exits at once.
What the agent does today
It enrols, learns its device id and heartbeat interval from the dashboard, and sends a heartbeat on that interval. CPU and memory reporting, and the browser terminal, are not built yet.
Combining device with other commands
1 invocation runs 1 command. The first word decides which, and everything after it belongs to that command. pinggy device connect start my-tunnel runs the agent and ignores start my-tunnel; it does not start a tunnel.
| Command | What happens |
|---------|--------------|
| pinggy device connect -l 3000 -b --all --remote-management <KEY> | Runs the agent in the daemon. Those flags parse and are ignored. No tunnel, no remote management. Only --token, --manage, -b and --foreground are read |
| pinggy device connect -b --foreground | Error, exit 1. The 2 flags contradict each other. Nothing runs |
| pinggy device start my-tunnel | Runs the agent, as connect does, and ignores my-tunnel. To start that tunnel, run pinggy start my-tunnel |
| pinggy device daemon stop | Error, exit 1. The verb after device is login, connect, start, stop, status, or remove |
| pinggy start device, pinggy stop device | device reads as a tunnel name. No new config can be called device, so nothing matches |
| pinggy config save device ... | Rejected. device is a reserved name |
| pinggy -l 3000 device | An ordinary tunnel. device is not a valid domain, so it warns Unknown extended option and is ignored |
| pinggy device connect --typo | Unknown options are rejected before anything runs |
| pinggy devices connect, or devices with anything | Error, exit 1: "pinggy devices" is now "pinggy device". Run: pinggy device connect. Nothing runs |
pinggy device and pinggy device --help print the command list. After a verb, --help is ignored, so pinggy device connect --help tries to connect.
Devices, tunnels, and the daemon
- By default the daemon runs the agent.
pinggy device connectandloginstart a daemon when none runs.pinggy daemon stopstops the agent with every tunnel, and so does a reboot. Every daemon start runs it again, untilpinggy device remove.pinggy device stopstops it until the daemon starts again. Withpinggy autostart on, the daemon starts with the computer, so the device comes back online after a reboot.pinggy device startorpinggy device connectstarts it again after a stop. - With
--foregroundthe agent is its own process. It never starts the daemon,pinggy daemon stopleaves it running, and Ctrl+C on it leaves every tunnel running. - 1 enrolment per machine. The newest successful connect overwrites
device.json, and a--tokenon the command line beats the stored one. - 1 agent per machine.
connectandloginrefuse while another terminal runs a--foregroundagent.--foregroundis refused while the daemon runs an agent. Stop that one first withpinggy device stop. pinggy device removestops a running agent, in the background or with--foregroundin another terminal, before it deletes the credential file. Then it removes the boot entry, when there is one.
Usage
Basic syntax: pinggy [options] [user@domain]
- user@domain is optional. Domain can be any valid domain supported by the service backend (e.g., ap.example.com).
Options
The CLI supports both SSH-style flags and more descriptive long flags. Below is a consolidated list (only public ones are shown here). For the most up-to-date help, run pinggy --help.
Port Forwarding
| Flag | Description | Example |
|------|-------------|---------|
| -R, --R | Local port forwarding (SSH-style) | -R0:localhost:3000 |
| -L, --L | Web debugger address (SSH-style) | -L4300:localhost:4300 |
Connection
| Flag | Description | Example |
|------|-------------|---------|
| -p, --server-port | Pinggy server port (default: 443) | --server-port 8080 |
| --type | Type of connection (e.g., tcp) | --type tcp |
| -l, --localport | Local endpoint [protocol:][host:]port | --localport https://localhost:8000 |
| -d, --debugger | Port for web debugger | -d 4300 |
| --token | Token for authentication | --token abc123 |
| --force | Forcefully close existing tunnels and establish a new tunnel | --force |
Logging
| Flag | Description |
|------|-------------|
| --loglevel | Logging level: ERROR, INFO, DEBUG |
| --logfile | Path to log file |
| --v | Print logs to stdout |
| --vv | Detailed logs (Node.js SDK + Libpinggy) |
| --vvv | Enable logs from CLI, SDK, and Libpinggy |
These flags apply to the CLI invocation. For daemon-wide log level and per-tunnel log files, see Logging.
Config (File-based)
| Flag | Description |
|------|-------------|
| --saveconf <file> | Create configuration file with provided options |
| --conf <file> | Load configuration from file (CLI flags override) |
File server
| Flag | Description |
|------|-------------|
| --serve <path> | Serve files from a local directory via simple web server |
AutoReconnect
| Flag | Description |
|------|-------------|
| --no-autoreconnect, -a | Disable automatic reconnection on failure. Enabled by default, and it keeps retrying until the tunnel is back (no attempt limit) |
Remote control
| Flag | Description |
|------|-------------|
| --remote-management <token> | Enable remote tunnel management |
| --manage <addr> | Remote management server (default: dashboard.pinggy.io) |
| --NoTui | Disable TUI in remote management mode |
Tunnel lifecycle
| Flag | Description |
|------|-------------|
| -b | Start the tunnel detached (daemon keeps it alive after the CLI exits). Pairs with pinggy start. |
| --all | Start every config marked auto-start. Pairs with pinggy start. |
| --auto | Mark a saved config as auto-start. Pairs with pinggy config save. |
Misc
| Flag | Description |
|------|-------------|
| --version | Print version and exit |
| -h, --help | Show help and exit |
Extended options
Extended options provide advanced controls. Specify them as positional values like x:https or w:192.168.1.0/24 alongside other CLI flags.
- x:https Enforce HTTPS-only (HTTP redirected to HTTPS).
- x:passpreflight | x:allowpreflight Allow CORS preflight to pass unchanged.
- x:reverseproxy Disable built-in reverse-proxy header injection.
- x:xff Add X-Forwarded-For.
- x:fullurl | x:fullrequesturl Include original request URL.
- x:haproxy | x:haproxy:v1 | x:haproxy:v2 Send HAProxy PROXY protocol header to the local server (default v1). TCP tunnels only.
- w:[,...] Whitelist IPs (IPv4 CIDR).
- k: Set Bearer token(s) for auth (repeatable).
- b:user:pass Add Basic Auth credentials (repeatable).
- a:Key:Val Add header.
- u:Key:Val Update header.
- r: Remove header.
Examples:
Enforce HTTPS and XFF for local HTTPS server on 8443: pinggy x:https x:xff -l https://localhost:8443
Allow only a local subnet: pinggy w:192.168.1.0/24 -l 8080
Send the real client IP to a PROXY-protocol-aware backend (TCP tunnels only): pinggy --type tcp x:haproxy:v2 -l 8080
To generate advanced CLI arguments, use Configure from Pinggy.io
Saving and loading configuration
- Save current options to a file:
pinggy -p 443 -L4300:localhost:4300 -t -R0:127.0.0.1:8000 [email protected] x:noreverseproxy x:passpreflight x:xff --saveconf myconfig.json- Use a config as base and override with flags:
pinggy --conf ./myconfig.json -p 8080Logging
The CLI has two layers of logging: per-invocation flags that affect what the current command prints, and daemon-wide log commands that read the persistent log files the daemon writes.
Per-invocation flags
Pass these on any command that starts or interacts with a tunnel.
pinggy -p 3000 --logfile ~/.pinggy/pinggy.log --loglevel INFO --vIf you pass --v, --vv, or --vvv without a log level, the default is INFO. If a logfile path is provided, the log directory is created if it does not exist.
Daemon and per-tunnel log files
The daemon writes its own log file and a separate log per tunnel under the platform log directory (see State and file locations). The native tunnel library logs to libpinggy/libpinggy.log in the same directory: one file for all tunnels.
Tail the daemon log
pinggy logs # last 100 lines of the daemon log
pinggy logs -f # follow new daemon log linesTail a tunnel log
pinggy logs my-tunnel # last 100 lines of that tunnel's log
pinggy logs my-tunnel -f # follow new lines (survives log rotation)Tail the native library log
pinggy logs libpinggy # last 100 lines of libpinggy.log
pinggy logs libpinggy -f # follow new linesThe file holds the library's lines for every tunnel. A tunnel or saved config named libpinggy keeps the name for its own log.
Print the log file path
pinggy log path # daemon log path
pinggy log path my-tunnel # path to a specific tunnel's log
pinggy log path libpinggy # path to the native library's logGet or set the daemon log level
pinggy log level # print current level
pinggy log level debug # set to debug, info, or errorSetting the level persists in daemon-config.json and applies to the daemon and any new tunnels. To pick up the new level on a tunnel that is already running, restart it with pinggy restart <name>.
State and file locations
Config dir varies by OS:
- Linux/macOS:
~/.config/pinggy/ - Windows:
%APPDATA%\pinggy\
It holds daemon.json (discovery), daemon-config.json (persisted settings), daemon-state.json (crash recovery), tunnels/ (saved configs), device.json (the Pinggy Devices credential, written 0600), and device-agent.json (the PID of a device agent running in a terminal).
Log dir varies by OS:
- Linux:
~/.local/state/pinggy-cli/logs/(honors$XDG_STATE_HOME) - macOS:
~/Library/Logs/Pinggy-CLI/ - Windows:
%LOCALAPPDATA%\Pinggy-CLI\Logs\
Use pinggy log path to print the exact resolved paths on your system.
File server mode
Serve a local directory quickly over a tunnel:
pinggy --serve /path/to/files
Optionally combine with other flags (auth, IP whitelist) as needed.
Signals and shutdown
- Foreground tunnel: Ctrl+C closes the TUI. The daemon arms a 5-second grace timer and stops the tunnel if no other CLI re-attaches.
- Detached tunnel (
-b): the CLI already exited. Stop it withpinggy stop <name|id>. - Everything at once:
pinggy daemon stopstops every tunnel and shuts the daemon down cleanly.daemon-state.jsonis cleared, so nothing replays on next start. - Device agent (
pinggy device connect): the CLI already exited. Stop the agent withpinggy device stop. No tunnel is affected. - Device agent in the foreground (
pinggy device connect --foreground): Ctrl+C ends the agent. It runs outside the daemon, so no tunnel is affected.
Versioning
This package follows semantic versioning. See package.json for the current version.
License
Apache License Version 2.0
