> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monolex.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Commands

> shell, exec, mosh, tunnel — the four ways to reach a remote machine.

## The four connection modes

```
┌────────────┬────────────────────────────┬────────────────────────┐
│  COMMAND   │  KIND                      │  USE WHEN              │
├────────────┼────────────────────────────┼────────────────────────┤
│ shell      │ interactive terminal (PTY) │ hands-on work          │
│ exec       │ one-shot + captured output │ scripts, automation    │
│ mosh       │ roaming interactive        │ survives Wi-Fi changes │
│ tunnel     │ raw TCP/UDP over P2P       │ ssh / scp / git / DB   │
└────────────┴────────────────────────────┴────────────────────────┘
```

<Note>
  Before you connect, the target machine must be **hosting** and both machines
  must be **logged in**. See [Connect your first machine](/vpncli/connect).
</Note>

## shell — interactive terminal

Open a full terminal on the remote machine.

```bash theme={null}
vpncli shell my-server
```

You get a normal interactive prompt, running on the far machine, over an
encrypted peer-to-peer link.

## exec — run a command, capture the output

Run a single command, stream its output back, and exit with the remote
command's exit code. No terminal UI — perfect for scripts and AI agents.

```bash theme={null}
vpncli exec my-server "hostname; uptime"
# → prints the remote hostname and uptime

vpncli exec my-server "test -f /etc/ready"
echo $?      # ← the REMOTE command's exit code
```

Because `exec` returns the remote exit code, it composes with shell logic:

```bash theme={null}
if vpncli exec my-server "systemctl is-active nginx"; then
  echo "nginx is up"
fi
```

## mosh — a terminal that roams

`mosh` gives you an interactive session that **survives network changes** —
switch Wi-Fi, close the lid and reopen, change locations, and your session is
still there.

```bash theme={null}
vpncli mosh my-server
```

vpncli starts the mosh server on the far machine for you (no ssh needed) and
hands you the session. The remote machine needs `mosh` installed.

## tunnel — forward a raw port

Forward a TCP (or UDP) port over the peer-to-peer link, so existing tools can
ride vpncli.

```bash theme={null}
# Use ssh over vpncli:
ssh -o ProxyCommand="vpncli tunnel %h %p" user@my-server

# Forward a local port to a remote service (e.g. a database):
vpncli tunnel my-server 5432 --listen 5432

# UDP (for mosh, DNS, and similar):
vpncli tunnel my-server 60001 --udp --listen 60001
```

## copy files too

Not a terminal, but the same P2P link moves files with no server in the middle:

```bash theme={null}
vpncli cp report.pdf my-server:/home/me/report.pdf
vpncli cp my-server:/var/log/app.log ./app.log
```

## Next

<CardGroup cols={2}>
  <Card title="Connect" icon="plug" href="/vpncli/connect">
    Install, log in, and host your first machine.
  </Card>

  <Card title="Security" icon="lock" href="/vpncli/security">
    How every mode stays encrypted.
  </Card>
</CardGroup>
