# Setup guide

> Install a Postern Hub from scratch with one command, choose how your devices reach it, create your account, add your first mailbox and get the apps.

Source: https://docs.posternmail.app/setup/

The Hub is the small server that Postern's apps connect to. It runs on a machine of yours,
keeps your mailboxes in sync and holds your settings, rules and sign-ins. This guide takes you
from an empty machine to your first mailbox. It takes about 15 minutes.

If you would rather have an AI coding agent do this for you, see
[Set up with an AI agent](https://docs.posternmail.app/setup-with-ai/).

## What you need

**A machine that stays on.** Rules, snoozes, scheduled sends and notifications only happen
while the Hub runs. Any of these works:

- a Raspberry Pi 4 or 5 with Raspberry Pi OS (64-bit), ideally with a USB SSD instead of an SD
  card;
- an old PC or laptop with Debian or Ubuntu;
- a small virtual server (VPS) from a hosting company, with 1 GB of memory or more;
- a NAS, if it runs Docker and lets you log in over SSH as an administrator.

The installer supports these systems, on 64-bit Intel or AMD (amd64) and 64-bit ARM (arm64):

| System | Versions |
|---|---|
| Debian | 12 or newer |
| Ubuntu | 22.04 or newer |
| Raspberry Pi OS | 64-bit, Bookworm or newer |
| Fedora | 40 or newer |
| RHEL, Rocky Linux, AlmaLinux | 9 or newer |

Plan for 1 GB of memory and a few GB of free disk. More details: [Requirements](https://docs.posternmail.app/requirements/).

**A terminal on that machine** with a user who may use `sudo`. Logging in over SSH from your
own computer is fine.

**Your mailboxes' passwords or app passwords.** Some providers need a little preparation, see
[step 7](https://docs.posternmail.app/setup/#7-add-your-first-mailbox).

## 1. Open a terminal on the machine

Sit at the machine, or log in to it from your computer. On macOS, Linux and Windows the command
is the same; replace the user and the machine's name or IP address with yours:

```sh
ssh pi@raspberrypi.local
```

> **Check:** you see a prompt on the machine, for example `pi@raspberrypi:~ $`.

> **If it did not work:** "Could not resolve hostname" means your computer does not know the
> name: use the machine's IP address instead (your router's device list shows it).
> "Connection refused" means SSH is off on the machine: on a Raspberry Pi, turn it on in
> Raspberry Pi Imager's settings or in `sudo raspi-config` under **Interface Options**.

## 2. Run the installer

```sh
curl -fsSL https://updates.posternmail.app/install | sudo sh
```

`sudo` asks for your password. The installer then looks at the machine and asks a few
questions, one screen each: **Machine**, **Access**, **Options** and **Review**. Nothing
changes until you confirm on the **Review** screen. Press **Enter** to take the suggested
answer.

What the installer does when you confirm:

- installs Docker, if you chose Docker and it is missing;
- downloads the Hub from Postern's download server and checks its signature, so only a Hub
  signed by Postern is installed ([how that works](https://docs.posternmail.app/updates/#where-updates-come-from));
- starts the Hub and, depending on your answers, Caddy, Tailscale or a Cloudflare Tunnel;
- waits until the Hub answers, then shows its address and a setup code.

Every command it runs is written to `/var/log/postern-install.log`.

> [!TIP]
> To read the installer before you run it, download it first:
>
> ```sh
> curl -fsSLo install.sh https://updates.posternmail.app/install
> less install.sh
> sudo sh install.sh
> ```

> **Check:** the screen shows **Postern Hub setup** and the steps
> **Machine › Access › Options › Review › Install › Finish**, then a summary of the machine.

> **If it did not work:** "curl: command not found" means curl is missing: install it with
> `sudo apt install curl` (Fedora and RHEL: `sudo dnf install curl`). "this is a 32-bit ARM
> system" means the Raspberry Pi runs the 32-bit system: install Raspberry Pi OS (64-bit) and
> start again.

## 3. Answer the questions

### How should the Hub run?

| Choice | Pick it when |
|---|---|
| **Docker (recommended)** | Almost always. The Hub runs in a container and updates arrive as new images. If Docker is missing, the installer installs it with Docker's own script. |
| **Native service** | The machine has little memory (under 1 GB), or you don't want Docker. The Hub is one program and a systemd service called `postern-hub`. |

Both update themselves and keep the same data. You cannot switch later without
[uninstalling](https://docs.posternmail.app/setup/#start-over-or-remove-the-hub) first; your data stays when you do.

### How will you and your devices reach the Hub?

This decides the address you open Postern at. You can change it later by running the installer
again.

| Choice | Good for | You need |
|---|---|---|
| **This machine's address on your network** | Trying Postern at home on a computer. | Nothing. But: plain HTTP, so no passkeys and no Google sign-in, and phones only reach it at home. |
| **A domain with HTTPS (Caddy)** | A Hub on a server on the internet, at your own address. | A domain name that points at this machine, and ports 80 and 443 open to the internet. |
| **Behind my own reverse proxy** | You already run nginx, Caddy, Traefik or similar. | Your proxy and a domain. The installer shows what to add to the proxy. |
| **Only on Tailscale (recommended)** | Most people at home. Private, with HTTPS, and it works on your phone away from home. | A free Tailscale account, and the Tailscale app on each device that uses Postern. |
| **Cloudflare Tunnel** | A public address without opening ports on your router. | A domain on Cloudflare. Cloudflare can read the traffic that passes through it. |

**Not sure? Pick Only on Tailscale.** It needs no domain and no open ports, nobody outside your
own devices can reach the Hub, and you get HTTPS, which passkeys and Google sign-in need.

What each choice asks, and what to prepare:

- **This machine's address on your network:** the address devices use. The installer suggests
  the machine's IP address. A name your router gives it, like `hub.lan`, also works and is
  better for Android phones ([why](https://docs.posternmail.app/reach/lan/#phones)). Give the machine a fixed IP address in
  your router, so the address doesn't change.
- **A domain with HTTPS (Caddy):** the domain, like `mail.example.com`, and optionally an email
  address for certificate notices. Before you start, create a DNS record (A or AAAA) that points
  the domain at the machine, and forward ports 80 and 443 to it if it is behind a router.
  Caddy gets the certificate from Let's Encrypt and renews it.
- **Behind my own reverse proxy:** the domain, and whether the proxy runs on this machine or on
  another one. At the end the installer shows what to forward and a ready Caddy example. For
  nginx and Traefik see [Reverse proxy](https://docs.posternmail.app/reach/reverse-proxy/).
- **Only on Tailscale:** nothing to type. First, in the Tailscale admin console under
  [DNS](https://login.tailscale.com/admin/dns), turn on **MagicDNS** and **HTTPS
  Certificates**. If Tailscale is not on the machine yet, the installer installs it and shows a
  link: open it and sign in. The Hub's address is then `https://<machine>.<tailnet>.ts.net`.
- **Cloudflare Tunnel:** the host name, and the tunnel's token. Create the tunnel in the
  Cloudflare dashboard (**Zero Trust**, **Networks**, **Tunnels**) and copy the token from the
  install command it shows. If `cloudflared` already runs on this machine, leave the token
  empty. Details: [Cloudflare Tunnel](https://docs.posternmail.app/reach/cloudflare/).

### Options and review

**Options** asks for the Hub's port on this machine (8080 unless something else uses it), the
folder for the Docker files (`/opt/postern`) and the update channel (**Stable updates**, or
**Beta updates** for new versions a little earlier). **Review** lists what will happen. Press
**Enter** to install.

> **Check:** the last screen says **Postern Hub 0.9.1 is running.** (with the current version),
> followed by **Open** with the address and **Setup code** with a code like `K7QF-2M9X-H4TC`.
> Write the code down.

> **If it did not work:** the installer shows the step that failed and its last lines of
> output; `/var/log/postern-install.log` has everything. Fix the cause and run the same command
> again: it picks up where things are and keeps your data. Common causes are in
> [When something goes wrong](https://docs.posternmail.app/setup/#when-something-goes-wrong).

## 4. Open the address

Open the address from the **Open** line in a browser, on any device that can reach the Hub:

- **Network address:** a device on the same network.
- **Tailscale:** a device signed in to the same tailnet.
- **Domain with Caddy:** any device, once the DNS record works. The first visit can take a few
  seconds while Caddy gets the certificate.
- **Your own proxy** or **Cloudflare Tunnel:** first finish the step the installer printed
  under **Point your proxy at the Hub** or **In Cloudflare**.

> **Check:** you see **Set up your Hub**.

> **If it did not work:** see [I cannot open the Hub from another device](https://docs.posternmail.app/troubleshooting/#i-cannot-open-the-hub-from-another-device).
> To try the Hub right away, forward its port over SSH from your computer and open
> `http://localhost:8080` there (the port only works while SSH stays open):
>
> ```sh
> ssh -L 8080:127.0.0.1:8080 pi@raspberrypi.local
> ```

## 5. Create your admin account

The setup page has three steps. The first account becomes the Hub's administrator.

1. **Name your Hub.** Type a **Hub name**, for example "Ellis Family Mail", and the **Setup
   code** from the installer. Click **Continue**.
2. **Create your account.** **Your name**, an **Email** and a **Password** of at least 10
   characters. The email is your sign-in name; it doesn't have to be a mailbox you'll connect.
   Click **Create account**.
3. **Add a mailbox.** Click **Add your first mailbox**, or **Skip for now** and do it later.

Lost the setup code? Show it again:

| Hub runs in | Command |
|---|---|
| Docker | `cd /opt/postern && sudo docker compose exec hub postern-hub setup-code` |
| Native service | `sudo cat /var/lib/postern/setup-code` |

> **Check:** you see your inbox (empty until you add a mailbox), and **Settings** has an
> **Admin** section.

> **If it did not work:** "That setup code isn't right" means a typo or an old code: show it
> again with the command above. "Cross-origin request rejected" means the address in the
> browser differs from the one the installer set up: open exactly the address from the
> **Open** line.

## 6. Back up the master key

The Hub encrypts your data with a master key that it created on its first start. Without the
key, your data and every backup are unreadable, to a thief and to you. Copy it now and keep it
somewhere else, for example in your password manager.

| Hub runs in | Copy the key to your home folder |
|---|---|
| Docker | `cd /opt/postern && sudo docker compose cp hub:/key/hub.key ~/hub.key` |
| Native service | `sudo install -m 0600 -o "$USER" /var/lib/postern-key/hub.key ~/hub.key` |

Move `~/hub.key` off the machine (for example with `scp`, or open it and paste the text into
your password manager), then delete it there with `rm ~/hub.key`.

> **Check:** the key is stored somewhere other than the machine, and not next to your data
> backups.

> **If it did not work:** "No such file" means the Hub has not started yet: go back to
> [step 3](https://docs.posternmail.app/setup/#3-answer-the-questions).

## 7. Add your first mailbox

Click **Add your first mailbox** after the setup, or later **Settings → Mailboxes → Add
mailbox**. The dialog asks **Where does your mail live?**: pick **Google**, **Microsoft**,
**iCloud** or **Other**, type your address and click **Continue** (for Google and Microsoft the
button says **Sign in with Google** or **Sign in with Microsoft**). The Hub finds the server
settings itself and offers the ways to sign in, the best one marked **Recommended**.

What each provider needs:

| Provider | Easiest way | Guide |
|---|---|---|
| Gmail | An app password. Needs 2-Step Verification on the Google account. | [Gmail](https://docs.posternmail.app/providers/gmail/) |
| Outlook.com, Microsoft 365 | A free app registration in Microsoft Entra, once per Hub. Passwords don't work at Microsoft. | [Microsoft](https://docs.posternmail.app/providers/microsoft/) |
| iCloud, Yahoo, AOL | An app-specific password. | [iCloud](https://docs.posternmail.app/providers/icloud/), [Yahoo](https://docs.posternmail.app/providers/yahoo/) |
| Fastmail | An app password or an API token. | [Fastmail](https://docs.posternmail.app/providers/fastmail/) |
| Any other provider | Your normal password, or an app password if the provider asks for one. | [Any IMAP mailbox](https://docs.posternmail.app/providers/imap/) |

> **Check:** the dialog says the mailbox is connected and shows a progress bar while your mail
> downloads. Recent mail appears first; older mail keeps arriving in the background.

> **If it did not work:** "The sign-in was rejected" usually means the provider wants an app
> password. "This way of signing in isn't set up on your Hub" means Google or Microsoft sign-in
> needs the app details in **Settings → Admin** first; the provider's guide shows how. More in
> [Connect mailboxes](https://docs.posternmail.app/providers/#errors-while-adding).

## 8. Install the apps

The web app is already there: it is the address you just opened. For your computer and phone,
get the apps from [the download page](https://posternmail.app/download/).

- **Desktop app:** enter the Hub's address when it asks, then sign in.
- **Phone:** in the web app, open **Settings → Devices → Connect a device** and scan the QR code
  with the Postern app. See [Pair a device](https://docs.posternmail.app/apps/pairing/).

With **Only on Tailscale**, every device needs the Tailscale app, signed in to your tailnet.
With **This machine's address on your network**, phones connect only at home, see
[LAN only](https://docs.posternmail.app/reach/lan/#phones).

## Updates

The Hub updates itself. It looks for a new version every 10 minutes, checks its signature,
waits until no mail is being sent or synced, then installs it and restarts. If the new version
does not start, it goes back to the old one. [Updates](https://docs.posternmail.app/updates/#the-hub) explains it, and how
to turn it off.

To update right now, run the installer with `--update`:

```sh
curl -fsSL https://updates.posternmail.app/install | sudo sh -s -- --update
```

To change how the Hub is reached, its port or the update channel, run the installer again
without options and choose **Change how it is set up**. Your data stays.

## Backups

The Hub backs itself up every 24 hours and keeps the last 7 backups. They sit next to its
data, so they don't help if the disk dies: copy them to another place. Everything the Hub has
is in two places, kept apart on purpose:

| Hub runs in | Data and backups | Master key |
|---|---|---|
| Docker | the Docker volume `postern_postern-data` (folder `/var/lib/docker/volumes/postern_postern-data/_data`, backups in `backups/`) | the volume `postern_postern-key` |
| Native service | `/var/lib/postern` (backups in `backups/`) | `/var/lib/postern-key` |

Copy the data folder somewhere else regularly; copy the key once, as in
[step 6](https://docs.posternmail.app/setup/#6-back-up-the-master-key), and keep it apart from the data. A backup without the key
is useless, and the key alone does nothing. [Backups and restore](https://docs.posternmail.app/admin/backups/) shows how to
copy backups off the machine automatically and how to restore one.

## When something goes wrong

**The installer stopped with an error.** It shows the step that failed and the last lines of
its output. The whole log is `/var/log/postern-install.log`. It is safe to run the installer
again once the cause is fixed. Frequent causes:

| Message | What to do |
|---|---|
| "something already listens on port 8080" | Another program uses the port. Choose another port in **Options**, or add `--port 8081`. |
| "port 80 is in use, and Caddy needs it" | A web server already runs on the machine. Choose **Behind my own reverse proxy** and add the Hub to that server. |
| "Install Docker (get.docker.com) did not work" | Docker's script does not support this system. Install Docker with [Docker's instructions](https://docs.docker.com/engine/install/), or choose **Native service**. |
| "Tailscale sign-in did not finish" | Run `sudo tailscale up`, open the link, then run the installer again. |
| "the signature ... does not match" | The download was changed or damaged. Nothing was installed. Try again later; if it stays, report it. |

**The Hub stopped answering.** Look at its status and log:

| Hub runs in | Status | Log |
|---|---|---|
| Docker | `cd /opt/postern && sudo docker compose ps` | `cd /opt/postern && sudo docker compose logs -f hub` |
| Native service | `systemctl status postern-hub` | `journalctl -u postern-hub -f` |

Then run the Hub's own check, which tests the settings, the data and the connections to your
mail providers, and says what to change:

| Hub runs in | Command |
|---|---|
| Docker | `cd /opt/postern && sudo docker compose exec hub postern-hub doctor` |
| Native service | `sudo -u postern sh -c 'set -a; . /etc/postern/hub.env; exec /usr/local/bin/postern-hub doctor'` |

See [Doctor](https://docs.posternmail.app/admin/doctor/) and [Troubleshooting](https://docs.posternmail.app/troubleshooting/) for what its messages
mean.

### Start over or remove the Hub

```sh
curl -fsSL https://updates.posternmail.app/install | sudo sh -s -- --uninstall
```

This stops and removes the Hub but keeps your data, the master key and the settings, so
installing again brings everything back. It prints the command to delete the data for good,
which cannot be undone.

## Installing without questions

Every answer has an option, and `--yes` runs the installer without asking anything, for
scripts or a second machine. Options go after `sh -s --`:

```sh
curl -fsSL https://updates.posternmail.app/install | sudo sh -s -- \
  --docker --access domain --domain mail.example.com --email you@example.com --yes
```

| Option | Meaning |
|---|---|
| `--docker`, `--native` | How the Hub runs. Default: Docker. |
| `--access MODE` | `lan`, `domain`, `proxy`, `tailscale` or `cloudflare`. Required with `--yes`. |
| `--address HOST` | `lan`: the address devices use. Default: the machine's IP address. |
| `--domain NAME` | `domain`, `proxy`, `cloudflare`: the host name. |
| `--email ADDRESS` | `domain`: email for certificate notices (optional). |
| `--proxy-elsewhere` | `proxy`: the proxy runs on another machine, so the Hub listens on the network. |
| `--tunnel-token TOKEN` | `cloudflare`: the tunnel token. Also read from `POSTERN_TUNNEL_TOKEN`. |
| `--port N` | The Hub's port on this machine. Default 8080. |
| `--dir DIR` | Docker: the folder for `compose.yaml` and `.env`. Default `/opt/postern`. |
| `--channel NAME` | `stable` (default) or `beta`. |
| `--version X.Y.Z` | Install this version instead of the newest. |
| `--yes` | Ask nothing; use the options and the defaults. |
| `--update` | Update an installed Hub. |
| `--uninstall` | Remove the Hub; data and settings stay. |

Tailscale signs in without a browser when the environment variable `TS_AUTHKEY` holds an
[auth key](https://tailscale.com/kb/1085/auth-keys).

What the installer writes:

| | Docker | Native service |
|---|---|---|
| Program | the image `ghcr.io/theoriuhd/postern-hub` | `/usr/local/bin/postern-hub` |
| Settings | `/opt/postern/.env` | `/etc/postern/hub.env` |
| Service | `/opt/postern/compose.yaml` | `/etc/systemd/system/postern-hub.service` |
| Caddy (domain) | the `caddy` service in `compose.yaml` | `/etc/caddy/postern.caddy`, imported by `/etc/caddy/Caddyfile` |
| Cloudflare Tunnel | `/opt/postern/compose.tunnel.yaml` | the `cloudflared` service |
| The installer's answers | `/etc/postern/install.conf` | `/etc/postern/install.conf` |

Every setting the Hub reads is in [Configuration](https://docs.posternmail.app/configuration/).

## Other ways to install

- **Docker Compose by hand:** download [compose.yaml](https://github.com/TheOriUHD/postern/blob/main/deploy/docker/compose.yaml), set the
  variables in `.env` as described in [Configuration](https://docs.posternmail.app/configuration/), and run
  `docker compose up -d`.
- **Build from source:** see [Build from source and development](https://docs.posternmail.app/development/).
- **Inside the desktop app:** the desktop app can run a Hub of its own while it is open, for
  trying Postern on one computer. See [Desktop app](https://docs.posternmail.app/apps/desktop/).
- **macOS:** the installer does not support Macs as servers. A Mac sleeps, and Docker Desktop
  needs a signed-in user. Use a Linux machine for a Hub that other devices rely on.
