# Sync, backup & pairing

Vaultport has no cloud of its own. To use the same vault on several devices, you point it at **storage you already control**. That storage only ever receives encrypted, integrity-protected files.

Open **Settings → Sync & backup**.

## Sync targets

Choose **Add sync target** and a storage type:

| Storage type                                                                               | Settings                                                                                       |
| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| **Synced folder** (iCloud Drive, Dropbox, Syncthing, Nextcloud desktop, a network share …) | The folder. Any folder that another app keeps in sync works                                    |
| **WebDAV** (Nextcloud, ownCloud, many NAS)                                                 | URL, username, password                                                                        |
| **S3-compatible** (AWS S3, MinIO, Cloudflare R2, Backblaze B2 …)                           | Endpoint (empty for AWS), bucket, region, optional prefix, access key ID and secret access key |
| **Git repository over SSH** (GitHub, GitLab, Gitea, any SSH server with Git)               | Repository, key or identity to sign in with, branch — see [Git over SSH](#git-over-ssh)        |

Credentials for the storage are stored as vault secrets that stay on this device. S3 endpoints must use HTTPS.

Press **Sync now** to sync a target. Each sync downloads the changes of your other devices, merges them, and uploads this device's new changes. The list shows when each target last synced and any problem it found.

## Git over SSH

A Git repository works as sync storage on every platform, phones included: Vaultport speaks the Git protocol itself over its own SSH connection, so no `git` program is needed.

1. **Create a repository** for the vault, e.g. a private GitHub repository `me/vault`. It can be empty.
2. **Choose a key.** Create or import one under **Keys** (a key stored in the vault; see below for security keys). Copy its public key and add it to the repository **with write access** — on GitHub: _Settings → Deploy keys → Add deploy key_, tick **Allow write access**. A deploy key only grants access to this one repository, which makes it a good fit. An account-wide key or an [identity](http://vaultport.niessen.dev/guide/keys.md) works too.
3. **Add the target:** storage type **Git repository over SSH**, then
   - **Repository**: the SSH address, `git@github.com:me/vault.git` or `ssh://user@host:2222/srv/vault.git`. HTTPS addresses are not supported.
   - **Sign in with**: the key or identity from step 2. Without one, desktop builds use the system SSH agent.
   - **Branch**: `vaultport-sync` by default. Sync data lives only on this branch; your other branches are never read or written, so the repository can hold other things too.
4. **Sync now.** On the first connection Vaultport shows the server's **host key** like for any new host. Compare the fingerprint with the one your provider publishes (GitHub lists them in its documentation) and trust it. The key is saved in [Known hosts](http://vaultport.niessen.dev/guide/known-hosts.md); if it ever changes, syncing stops with a warning instead of connecting.

Each sync fetches the branch, merges it with this device's copy, and pushes. If another device pushed in the meantime, Vaultport fetches and merges again. The repository's history only ever contains encrypted segment files and commits by "Vaultport".

A local copy of the branch is kept in the app's data folder; removing the target deletes it. Security keys (FIDO2) work on the device they are plugged into; for [pairing](#pair-a-new-device), use a key stored in the vault.

## Conflict-free by design

The vault is a CRDT: every change is an operation with a timestamp from a hybrid logical clock, and every field is resolved last-writer-wins. Two devices that have seen the same operations always end up with identical data, whatever order the operations arrived in. You can edit on your laptop and phone while offline and sync later — there are no merge dialogs and no "conflicted copy" files.

## What the storage sees

Only immutable **segment files**, one series per device, named by vault id, device id and counter. Each segment is encrypted with XChaCha20-Poly1305 under a key derived from your vault key, and chained to the device's previous segment by a SHA-256 hash.

The storage provider therefore cannot read your data, and it cannot forge, reorder or silently drop changes either: Vaultport detects and reports missing segments (gaps), rollbacks to an older state, tampered files and forks, and stops applying that device's changes until the problem is resolved. Details are in the [sync protocol](http://vaultport.niessen.dev/security/sync.md).

Conflict copies made by sync tools and unexpected files are ignored.

## Pair a new device

Pairing copies the vault to a new phone, tablet or computer **directly over your local network** — no sync storage, account or server is involved. Both devices must be on the same network (the same Wi-Fi or LAN).

**On the device that has the vault:**

1. **Settings → Sync & backup → Pair a device.**
2. A **QR code** and, separately, an 8-character **pairing code** such as `K7QM-2XPA` appear, with "Waiting for the other device…". They are valid for 10 minutes. Keep the window open: the device only accepts a connection while it is shown.

**On the new device:**

1. On the lock screen choose **I already have a vault → Pair with another device**.
2. Scan the QR code with the camera and paste the **pairing text**, or copy the text under the QR code across.
3. Enter the pairing code, a name for the vault on this device and a master password.

The new device connects to the other one, both check the code, and the vault is transferred — both screens show the progress. The new device becomes a full copy (a _replica_) of the same vault with its own master password.

**Keeping the devices in sync afterwards:** if the device that has the vault has a [sync target](#sync-targets), the new device also gets the **first sync target with its credentials** and keeps syncing through it. For a Git target this includes a copy of its key (or identity password) for the first sync, and the server's trusted host keys, so the new device does not have to ask about them. Without a sync target the transfer is a **one-time copy**: changes made afterwards stay on the device where they were made until you add the same sync storage on both devices (they then merge automatically) or pair again.

Data that is marked to stay on its device — for example the credentials of each device's own sync targets — is never transferred, except the sync target credentials described above.

### If the devices cannot reach each other

- Both devices must be on the **same network**. Guest Wi-Fi and some company networks isolate devices from each other ("client isolation"); a phone on mobile data cannot reach a computer at home.
- **Windows** may ask whether Vaultport may accept connections the first time you pair: allow it on **private networks**. The firewall rule only matters while the pairing window is open — Vaultport does not listen at any other time.
- **iOS** asks for permission to find devices on the local network; allow it (Settings → Privacy & Security → Local Network → Vaultport).
- A VPN on either device can route the connection elsewhere; turn it off while pairing.

Copying the pairing text to a device on **another network** does not work. To set up a device elsewhere, add a [sync target](#sync-targets) on both devices, or move an [encrypted backup](#encrypted-backups) across and restore it there.

> **Pair in private**
>
> Someone who sees _both_ the QR code and the pairing code, and is on the same network, could pair instead of your device. The QR code alone is useless: it contains no key, and every guess of the code needs a connection to your device, which stops after three wrong codes. Do not share screenshots or screen recordings of the pairing screen. See [device pairing](http://vaultport.niessen.dev/security/sync.md#device-pairing) for the protocol.

## Encrypted backups

**Export** writes the whole vault to one `.vaultport` file, protected by a passphrase of its own (at least 8 characters). The file is encrypted with Argon2id and XChaCha20-Poly1305, and any modification is detected.

To restore, choose **Restore from backup** on the lock screen (or **Import** in Sync & backup) and pick the file. It becomes a new vault on this device, protected by the backup passphrase, which you can change afterwards. Because the file contains the vault's own operations, a restored vault is the same replica and can keep syncing with your other devices.

Keep at least one backup somewhere safe: without your master password, a backup passphrase or another device, nobody can recover your vault.
