# Shared users and shared storage

Two servers are only a replacement for each other if a user finds the same account and the same files on both. The servers of a [cluster](High-Availability.md) keep each other's settings the same by themselves. The **files** are a different matter, and they are yours to arrange. This page is about both.

## Users

| Users are kept | All servers have them through |
|---|---|
| in the server's own files (the usual) | [replication](Replication.md): a change on one server is on the others within a second |
| in an outside directory: LDAP, Active Directory, SAML, OpenID Connect | the directory itself: every server asks the same one. Set the plugin up the same on each; its settings replicate with the preferences. |
| in a database of your own, by the SQL users option | that database: every server reads the same one |

With users in the server's own files there is nothing to decide. Check only that **User Manager changes** is on in [Preferences, Replication](Prefs-Replication.md#replicated-items), and that a server which joined later got the existing users copied: [Joining a server](Cluster-Joining.md#copying-what-was-there-before).

With users in an outside place, replication of users has nothing to carry for them. The local accounts that remain, the administrators and the templates, still replicate.

Things that belong to a user and must be the same everywhere:

| | |
|---|---|
| SSH public keys kept as files | on storage all servers reach, under the same path |
| the user's home folder | the same address on every server: see below |
| a second factor's secret | part of the user: replicated |
| shares the user made | **Shares**, replicated |

## Files

The cluster does not copy files between servers. A file uploaded through server A is on the storage A wrote it to, and server B serves it only if B reaches the same storage.

### What "the same storage" can be

| Storage | How the servers use it | Notes |
|---|---|---|
| a file server or NAS, mounted on every server | a user's folder is a local path, `file:///mnt/files/alex/`, the same on all | the mount must be there before the server starts, under the same path everywhere |
| a file server, reached by the server itself | a user's folder is an address, `smb://…` or `nfs://…`: see [VFS: SMB](VFS-SMB.md), [VFS: NFS](VFS-NFS.md) | nothing to mount; each server connects by itself |
| object storage: S3, Azure, Google Cloud Storage | a user's folder is an address, `s3://…`: see [VFS: S3](VFS-S3.md) | available from anywhere, also from two sites |
| a cluster file system on the servers' own disks | a local path | the file system does the sharing |

All of these work. What does not work is a local disk in each server: the user's files would be on whichever server they happened to reach.

### The paths must be the same

A user's folder is stored as an address in the user. The user replicates; the address goes with it, letter for letter. So `file:///mnt/files/alex/` must mean the same folder on every server.

- Mount shared storage under the same path on all servers.
- On Windows, use the same drive letter, or better a UNC path, on all.
- Prefer addresses that do not depend on the machine: `smb://`, `nfs://`, `s3://`.

### What else lives on disk

Besides the users' files, a few things of the server itself should be on storage that all servers share:

| | Why | Where it is set |
|---|---|---|
| the activity record that reports read | so that a report on any server covers all of them | **Folder** in [Preferences, Reporting](Prefs-Reporting.md#storage); each server with its own **Node number**. See [The store on disk](Reports-Store.md#in-a-cluster). |
| the search catalog | so that a search finds files indexed by any server | with the activity record, or its own folder: [Search and the file index](Search-Index.md) |
| preview pictures | so that a thumbnail made on one server is there on the other | the preview folder: [Preferences, Preview](Prefs-Preview.md) |
| files of uploads in progress, where a resume shall work on another server | a broken upload can only be resumed where its part is | the user's folder itself, on shared storage |
| keys and certificates that settings name by path | the settings replicate, the files they point to do not | the same path on every server, or on shared storage |

Each server keeps for itself: its own settings folder with its identity, its logs, and its job engine's work files.

### Jobs and paths

Jobs replicate, and with them the addresses in their tasks. A job that reads `file:///data/in/` runs on whichever server's engine takes it, and needs that path there. Either the path is on shared storage, or the job is tied to the server that has it: see [Jobs in a cluster](Jobs-Engines-Cluster.md#sending-a-job-to-a-certain-server).

## When the storage is the weak point

A cluster of two servers on one file server has moved the single point of failure from the server to the storage. Decide how much that matters:

- A NAS with two heads, or a storage service with its own redundancy, closes it.
- Object storage in a cloud is redundant by itself.
- Two sites need storage that spans both, or a copy between them.

For two servers with **separate** disks, the server can mirror what users do onto a second server and keep a journal for what could not be passed on: [VFS replication](Prefs-Replication.md#vfs-replication). It is for that rare case, and it is slower and more fragile than shared storage.

## Locks and two servers

Two users can write the same file through two servers at the same moment. The servers do not coordinate that between themselves; the storage decides who wins, as it would for any two programs.

- Give partners their own folders, so that the question does not come up.
- Uploads that use a temporary name and rename at the end never show half a file to the other server.

## Checking it

1. Upload a file through server A. List the folder through server B.
2. Change a user's password on A. Log in on B with the new one.
3. Make a share on A. Open its link on B.
4. Stop A. Do all three on B.

## Things to know

- **The same SSH host keys on all servers**, or SFTP programs warn that the server's key changed when they land on another. The host keys are files of each server: copy the key files of the first server to the others, under the same path, before users connect.
- **The same TLS certificate on all**: [Let's Encrypt in a cluster](HA-Lets-Encrypt.md).
- **Quotas** are counted where the files are. With shared storage, both servers see the same use.
- **Time.** Keep all servers' clocks right. File dates, logs and reports are compared across servers.
- **Nothing here was run for this page**: it is advice built on how users, addresses and replication work, as the pages it links to describe them.
