# Ports and paths

> Every port the Hub and its tools use, and every file and folder they create for each install method, with owners and modes.

Source: https://docs.posternmail.app/reference/ports-and-paths/

This page lists the network ports Postern uses and where each install method keeps the program,
its configuration, its data and its key. Use it when you set up a firewall, plan backups or look
for a file.

## Ports the Hub listens on

| Port | When | Notes |
|---|---|---|
| `8080/tcp` | Always, unless changed with `POSTERN_LISTEN` | HTTP: the web app, the API and the WebSocket. The built-in default `:8080` listens on every interface; the systemd unit and Docker publish it on `127.0.0.1` only. |
| `443/tcp` | With `POSTERN_TLS_DOMAIN` and `POSTERN_LISTEN` left at exactly `:8080` | HTTPS with a Let's Encrypt certificate. |
| `80/tcp` | With `POSTERN_TLS_DOMAIN` | ACME HTTP challenges and the redirect to HTTPS. If the Hub cannot bind it, it logs `http->https redirect listener failed` and keeps running. |
| `POSTERN_LISTEN` with TLS | With `POSTERN_TLS_CERT` and `POSTERN_TLS_KEY` | HTTPS on the listen address; nothing on port 80. |

Ports below 1024 need root or the `CAP_NET_BIND_SERVICE` capability. See
[Configuration](https://docs.posternmail.app/configuration/#built-in-https).

**Docker Compose:**
| Host port | Container | What |
|---|---|---|
| `127.0.0.1:8080` (`POSTERN_BIND`) | `hub:8080` | The Hub. `POSTERN_BIND=8080` publishes it on every interface. |
| `80/tcp`, `443/tcp`, `443/udp` | `caddy` | Only with the `caddy` profile: HTTPS (HTTP/3 on UDP) and certificate challenges. |

The image's health check fetches `http://127.0.0.1:8080/api/v1/info` inside the container every
30 seconds.
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
The unit sets `POSTERN_LISTEN=127.0.0.1:8080`: only programs on the same machine (a reverse
proxy, `tailscale serve`, `cloudflared`) reach the Hub. Open a firewall port only if you set
`POSTERN_LISTEN=0.0.0.0:8080` for LAN access, or use built-in HTTPS (80 and 443). On Fedora
with firewalld:

```sh
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
```
**Desktop app (built-in Hub):**
The built-in Hub listens on `127.0.0.1:<port>`, a free port the app picks on first start and
then keeps (stored in `desktop.json`). The app opens it as `http://localhost:<port>`. It is
reachable only from that computer; there is nothing to open in a firewall.

The app's mail engine for a remote Hub also listens on `127.0.0.1:<port>`, one remembered port
per Hub.

## Ports the Hub connects to

The Hub (and the apps in direct mode) open outgoing connections to:

| Destination | Port | Why |
|---|---|---|
| Your IMAP and SMTP servers | as configured (typically 993, 465 or 587) | Password and app-password mailboxes. |
| `gmail.googleapis.com`, `oauth2.googleapis.com` and other Google API hosts | 443 | Gmail with Google sign-in. |
| `imap.gmail.com` | 993 | The Gmail "doorbell" that wakes sync when the inbox changes. |
| `graph.microsoft.com`, `login.microsoftonline.com` | 443 | Microsoft 365 and Outlook.com. |
| `outlook.office365.com` | 993 | The Microsoft "doorbell" (IMAP IDLE). |
| Your JMAP provider | 443 | JMAP mailboxes (Fastmail and others). |
| The push relay (`POSTERN_RELAY_URL`) | 443 | Mobile push. |
| Web Push services of browsers | 443 | Browser notifications. |
| Let's Encrypt | 443 | With `POSTERN_TLS_DOMAIN`. |
| Your identity provider | 443 | With single sign-on. |
| Any web server | 80, 443 | The image proxy (remote images you choose to load), one-click unsubscribe, autodiscovery, rule webhooks and alert channels. Private addresses are refused unless `POSTERN_DEV` (or `POSTERN_RULES_ALLOW_LAN` for webhooks and alerts). |

## Other ports

| Port | Program | When |
|---|---|---|
| `8090/tcp` | Push relay (`postern-relay`) | Default `RELAY_LISTEN` when you run your own relay. See [Run your own relay](https://docs.posternmail.app/relay/run-your-own/). |
| `127.0.0.1:1143` | `devmail` IMAP | Development only. |
| `127.0.0.1:1025` | `devmail` SMTP | Development only. |
| `127.0.0.1:1080` | `devmail` HTTP control API | Development only. |
| `5173` | Vite dev server of the web app | Development only. |
| `4173` | `vite preview` (web app, website) | Development only. |

`devmail` has no TLS and fixed passwords: never expose it. See
[Build from source](https://docs.posternmail.app/development/#run-it-locally).

## Program, configuration and service

**Docker Compose:**
| What | Path |
|---|---|
| Compose project | `~/postern/compose.yaml` (copied from [deploy/docker/compose.yaml](https://github.com/TheOriUHD/postern/blob/main/deploy/docker/compose.yaml)) |
| Configuration | `~/postern/.env`, `~/postern/compose.override.yaml` |
| Image | `ghcr.io/theoriuhd/postern-hub:local`, built from the repository (no images are published yet) |
| Binary in the image | `/usr/local/bin/postern-hub` (and the link `/usr/local/bin/mailclient-hub`) |
| User in the container | UID and GID `10001` (`postern`) |
| Container file system | read-only, with a `tmpfs` on `/tmp`; all capabilities dropped |
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
| What | Path | Owner and mode |
|---|---|---|
| Binary | `/usr/local/bin/postern-hub` (future packages: `/usr/bin/postern-hub`) | `root`, `0755` |
| Source checkout | `~/postern` | your user |
| Build output | `~/postern/hub/bin/postern-hub` | your user |
| Unit | `/etc/systemd/system/postern-hub.service` (future packages: `/usr/lib/systemd/system/`) | `root`, `0644` |
| Local overrides | `/etc/systemd/system/postern-hub.service.d/override.conf` (`sudo systemctl edit postern-hub`) | `root` |
| Configuration directory | `/etc/postern` | `root:postern`, `0750` |
| Configuration | `/etc/postern/hub.env` | `root:postern`, `0640` |
| Service user | `postern` (system user, no login shell, home `/var/lib/postern`) | |

The unit runs with `UMask=0077`, so every file the Hub creates is readable by `postern` only.
It uses `ProtectSystem=strict`: the Hub can write only to its state directories (and to paths
you add with `ReadWritePaths=`).
**Desktop app (built-in Hub):**
The Hub binary is bundled in the app's resources:

| System | Path |
|---|---|
| macOS | `/Applications/Postern.app/Contents/Resources/hub/hub` |
| Windows | `hub\hub.exe` in the `resources` folder of the installed app |
| Linux | `hub/hub` in the `resources` folder of the installed app |

Builds without a bundled Hub do not offer **Run a Hub on this computer**.

## Data directory

**Docker Compose:**
The data directory is `/data` in the container, stored in the volume `postern_postern-data`
(`POSTERN_DATA_VOLUME`). The directory is owned by UID `10001`, mode `0700`.
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
The data directory is `/var/lib/postern`, created by systemd (`StateDirectory=`) with owner
`postern:postern` and mode `0700`.
**Desktop app (built-in Hub):**
The data directory is `hub-data/` in the app's data folder (see
[Desktop app data folder](https://docs.posternmail.app/reference/ports-and-paths/#desktop-app-data-folder)), mode `0700`.

Its contents, the same for every method:

| Path | Mode | What |
|---|---|---|
| `hub.db` | `0600` | The SQLite database: users, settings, mailboxes, message index, rules, encrypted credentials and Hub secrets. |
| `hub.db-wal`, `hub.db-shm` | | SQLite's write-ahead log, present while the Hub runs. Part of the database: never delete them by hand. |
| `blobs/` | `0700` | Encrypted files: `blobs/mail/<user>/` (message bodies and attachments), `blobs/uploads/<user>/` (attachments being composed), `blobs/custody/<user>/` (mail kept by rules: captured mail and redirect sources). |
| `backups/` | `0700` | Default backup directory (`POSTERN_BACKUP_DIR`), see below. |
| `acme/` | | Let's Encrypt account and certificates, only with `POSTERN_TLS_DOMAIN`. |
| `hub.lock` | `0600` | Lock file held by the running Hub (it contains its process ID). A leftover file never blocks a start: the operating system releases the lock when the process ends. |
| `setup-code` | `0600` | The first-run setup code. Exists only until the first user is created. |
| `pre-restore-<time>/` | `0700` | Left by `postern-hub restore`: the database and blobs from before the restore. Delete it once the restored Hub works. |
| `hub.key` | `0600` | The master key, **only** if `POSTERN_KEY_FILE` is not set. Every install method here keeps it elsewhere. |

The Hub creates the data directory with mode `0700` if it is missing. `postern-hub doctor` warns
when the directory, the database or the key file can be read by other users.

## Backups

Each backup is a directory in `POSTERN_BACKUP_DIR` (default `<data dir>/backups`):

| Path | What |
|---|---|
| `backup-YYYYMMDD-HHMMSS/` | One backup (time in UTC). A second backup in the same second gets `-2`, `-3`. |
| `backup-.../hub.db` | Copy of the database (`0600`). |
| `backup-.../blobs/` | The encrypted files, hard-linked to the originals when the file system allows it (so a backup on the same disk takes little space). |
| `backup-.../manifest.json` | Format, product, version, time, applied migrations, number and size of blob files, and a note that the key is not included. |
| `.backup-...partial/` | A backup being written. Removed if it fails. |
| `pre-migrate-YYYYMMDD-HHMMSS.db` | The database before a schema migration, written automatically at start. Restore it with `postern-hub restore --from <file>`. |

Scheduled backups keep the newest `POSTERN_BACKUP_KEEP` (default 7) `backup-*` directories;
`pre-migrate-*.db` files are never pruned. See [Backups](https://docs.posternmail.app/admin/backups/).

**Docker Compose:**
Backups are inside the data volume at `/data/backups`. To copy one out of the container:

```sh
cd ~/postern && docker compose cp hub:/data/backups/backup-20261205-030000 ./backup-20261205-030000
```
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
Backups are in `/var/lib/postern/backups`. A `POSTERN_BACKUP_DIR` outside `/var/lib/postern`
must be writable by `postern` and listed in the unit with `ReadWritePaths=`.
**Desktop app (built-in Hub):**
Backups are in `hub-data/backups/` in the app's data folder.

## Master key

The master key file decrypts everything in the data directory and in every backup. It is never
part of a backup. Keep a copy somewhere else. See [Encryption](https://docs.posternmail.app/security/encryption/).

**Docker Compose:**
`/key/hub.key` in the container, stored in the volume `postern_postern-key`
(`POSTERN_KEY_VOLUME`). Mode `0600`, owner UID `10001`. To copy it out:

```sh
cd ~/postern && docker compose cp hub:/key/hub.key ./hub.key
```
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
`/var/lib/postern-key/hub.key`, in a separate directory (`postern:postern`, `0700`) created by
systemd, so a copy of the data directory alone cannot decrypt anything. File mode `0600`.
**Desktop app (built-in Hub):**
`hub-key/hub.key` in the app's data folder, mode `0600`, in its own folder (mode `0700`).

Files next to the key:

| File | Left by |
|---|---|
| `hub.key.tmp` | Writing a key file (renamed to `hub.key` when complete). |
| `hub.key.bak` | `postern-hub rotate-key`: the old key. Older backups need it. |
| `hub.key.new` | `postern-hub rotate-key` when it fails halfway. Keep it: the error says whether the database needs it. |
| `hub.key.bak-YYYYMMDD-HHMMSS` | `postern-hub keygen --force`: the overwritten key. |

A plain key file starts with `mailclient-hub-key-v1:`, a sealed one (protected by a
passphrase) with `mailclient-hub-sealed-key-v1:`. The prefix kept its old name.

## Logs

**Docker Compose:**
The Hub logs to standard error, which Docker collects: `docker compose logs -f hub`.
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
The Hub logs to standard error, which the journal collects: `sudo journalctl -u postern-hub -f`.
**Desktop app (built-in Hub):**
The built-in Hub logs to `logs/hub.log` in the app's data folder.

See [Logs](https://docs.posternmail.app/admin/logs/).

## Desktop app data folder

The desktop app keeps everything in one folder:

| System | Folder |
|---|---|
| macOS | `~/Library/Application Support/Postern` |
| Windows | `%APPDATA%\Postern` |
| Linux | `~/.config/Postern` |

An install from before the rename keeps using its `MailClient` folder until a `Postern` folder
exists.

| Path | Mode | What |
|---|---|---|
| `desktop.json` | `0600` | The app's own settings: the Hub you use and recent Hubs, the mode, window positions, the last view, the remembered local ports and the app's options. |
| `hub-tokens.json` | owner only | Device tokens for direct mode (and Cloudflare Access headers), one per Hub, encrypted with the system keychain (macOS Keychain, Windows DPAPI, Linux Secret Service or KWallet). Without a keychain the token is kept in memory only and you sign in again after a restart. |
| `engine/<hub>/` | `0700` | The mail engine's data for one Hub (`<host>[-port]-<hash>`): `engine.db`, `engine.key`, `engine.lock` and `blobs/`. This is the mail kept on this computer. Deleted when the Hub signs the device out. |
| `hub-data/` | `0700` | The built-in Hub's data directory (see [Data directory](https://docs.posternmail.app/reference/ports-and-paths/#data-directory)). |
| `hub-key/hub.key` | `0600` | The built-in Hub's master key. |
| `logs/desktop.log` | `0600` | The app's own log. Moved to `desktop.log.1` when it passes 5 MB. |
| `logs/mail.log` | `0600` | The mail engine's log. Moved to `mail.log.1` when it passes 10 MB. |
| `logs/hub.log` | `0600` | The built-in Hub's log. Moved to `hub.log.1` when it passes 10 MB. |

Electron also keeps its own caches and browser storage in this folder. Attachments you open are
saved to `Postern Attachments` in the system's temporary folder.
