# Connecting over SSH

https://instabox.sh/docs/ssh.md

With the CLI, or one ssh line for any terminal.

### With the CLI
```
instabox ssh dev                 # certificate, known_hosts and ssh in one step
instabox ssh dev -- uname -a     # run one command
instabox mosh dev                # like instabox ssh, with mosh
instabox ssh-config dev          # print a ~/.ssh/config Host block
instabox ssh-cert dev            # refresh only the certificate
```

### Pasting images
In `instabox ssh` on macOS, or Linux with `xclip` or `wl-paste`, Ctrl+V with an image on your computer's clipboard uploads it to the machine's `/tmp` and pastes its path, which Claude Code attaches as an image. Ctrl+C cancels a slow upload. A clipboard without an image sends Ctrl+V as usual; so that Ctrl+V reaches vim (visual block) or readline (quoted insert) while an image is on the clipboard, use `--no-paste` (or set `INSTABOX_NO_PASTE=1`), which turns this off. Only PNG images are pasted (a JPEG on the clipboard sends Ctrl+V as usual), and a failed paste rings the terminal bell.

### Port forwarding
`instabox port-forward dev 8080:3000` (or `forward`) makes port 3000 in the machine reachable at `http://127.0.0.1:8080` on your computer until you press Ctrl-C. `LOCAL` defaults to `REMOTE` (`instabox port-forward dev 3000`), one command can forward several ports (`instabox port-forward dev 8080:3000 5432`), and `--remote 3000 --local 8080` spells the same forward as flags. It is `ssh -N -L` with the instabox certificate, so it reaches any TCP service, and only you can use it: it listens on 127.0.0.1 unless `--address` (or `--bind`) says otherwise. For a URL other people can open, public or token-gated, use [ports](https://instabox.sh/docs/ports.md) instead.

### From any terminal, without the CLI
A machine's **Connect** section has **SSH tokens**: **Create token** gives one `ssh ibssh_…@<host>` line to paste anywhere, no CLI or SSH key needed. It stays in that section, ready to copy, and works until you revoke it (or for the time you pick). From the CLI: `instabox ssh-token dev`. The first time, ssh asks you to confirm the gateway's host key.

### mosh
[mosh](https://mosh.org) keeps a session alive through sleep, network changes and packet loss. Install it on your computer (macOS: `brew install mosh`), then run `instabox mosh dev` or the mosh command **Create token** shows. Snapshots made before mosh was added need `sudo apt install mosh` once.

### Copying large files
For large uploads use `instabox push` or `instabox cp` (the HTTP API, parallel-friendly: a file of 64 MiB or more goes up as 4 parallel PUTs), not scp or rsync over `ssh.instabox.sh`, which keeps about 2 MiB in flight per connection and so slows with distance. Measured: at a 5 ms round trip both paths do ~104 MB/s; at 305 ms the API does 11-13 MB/s per stream and SSH 3-6 MB/s; 4 parallel API PUTs did 39 MB/s total.

### How it works
The instabox gateway terminates SSH: `ssh -p <port> <machine-id>@<host>`, with a short-lived user certificate, and a known_hosts line `@cert-authority [<host>]:<port> <host CA key>` to trust the gateway. It relays mosh's UDP too, so only the gateway has to be reachable.
- Supported: sessions (pty, shell, exec, subsystem, env, signals) and local port forwarding.
- Not supported: agent forwarding, X11, remote forwarding.
- Connections close when the machine stops, pauses or is deleted.
