# Self-Hosting

While we offer a hosted, encrypted and secure server at [Atuin](https://atuin.sh/), we also provide
a self-hosted version of the Atuin server.

## Requirements

- You need to be able to run a binary or :docker: Docker container on a server.
- You must have either a :postgres: PostgreSQL, :mysql: MySQL or :sqlite: SQLite database.

## Quick Start

The server is distributed as a separate binary, `atuin-server`, pre-built and
available on [Github releases](https://github.com/atuinsh/atuin/releases).

```shell
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/atuinsh/atuin/releases/latest/download/atuin-server-installer.sh | sh
```

:::caution
If you're self hosting, we **strongly** suggest you stick to tagged releases,
and don't follow `main` or `latest`

Follow the GitHub releases, and please read the notes for each release. Most of
the time, upgrades can occur without any manual intervention. Rarely, there may
be additional steps necessary.
:::

You must [configure the database](#configuration) path in your
`~/.atuin/server.toml`:

```toml
db_uri="postgres://user:password@hostname/database"
```

Then, start the server with:

```shell
atuin-server start
```

## TLS

We **strongly** urge you enable TLS with Atuin. Without TLS, passwords are sent
plaintext, which is wildly insecure.

For TLS/HTTPS support, we recommend using a reverse proxy such as
[nginx](https://nginx.org/), [Caddy](https://caddyserver.com/), or
[Traefik](https://traefik.io/traefik) in front of the Atuin server.

## Administration

`atuin-server` supports some administration tools.

### User Management

While `open_registration` is `true`, anyone who can reach the server can
register. To keep a server private, leave it `false` and create accounts on the
server instead:

```shell
atuin-server admin user create --email alice@example.com alice
```

You can also delete users as well as change their passwords.

```shell
atuin-server admin user set-password alice
atuin-server admin user delete alice
```

See [`atuin-server admin`](/reference/cli/atuin-server/#atuin-server-admin).

## Configuration

The server's config lives at `~/.atuin/server.toml`, separate from the client's
config.

It looks something like this for PostgreSQL:

```toml
host = "0.0.0.0"
port = 8888
open_registration = true
db_uri="postgres://user:password@hostname/database"
```

> [!TIP]
>
> Alternatively, you can provide configuration options with environment
> variables.
>
> ```text
> ATUIN_HOST="0.0.0.0"
> ATUIN_PORT=8888
> ```
>
> Environment variables take precedence.

You **must** configure the database as Atuin can't proceed without one. You
can do so either in `server.toml` or via the environment variable:

Using `server.toml`:

```toml
db_uri="postgres://user:password@hostname/database"
```

Using `server.toml`:

```toml
db_uri="sqlite:///config/atuin.db"
```

**Note that atuin will create this file if it does not exist.**

Using `server.toml`:

```toml
db_uri="mysql://user:password@hostname/database"
```

:::note[Support]

MySQL is currently considered a tier-two database meaning that,
although we support it, issues are deprioritized in favor of tier-one
databases -- PostgreSQL and SQLite.
:::

> [!TIP]
>
> You can use the `db_password_file` if you want to pass the DB password from a
> file, eg. if you are using
> [k8s](https://kubernetes.io/docs/concepts/configuration/secret/) or similar:
>
>
> ```toml
> db_uri="mysql://user@hostname/database"
> db_password_file="/run/secrets/atuin_db_password"
> ```

### Configuration Options

| Parameter              | Description                                                                        |
| ---------------------- | ---------------------------------------------------------------------------------- |
| `db_uri`               | A valid database URI, for saving history (required, no default)                    |
| `db_password_file`     | A file holding the database password, kept out of `db_uri` (default: none)         |
| `host`                 | The host to listen on (default: 127.0.0.1)                                         |
| `port`                 | The TCP port to listen on (default: 8888)                                          |
| `open_registration`    | If `true`, accept new user registrations (default: false)                          |
| `path`                 | A path to prepend to all routes of the server (default: empty)                     |
| `trusted_proxies`      | Reverse proxies whose client address header is trusted (default: empty)            |
| `trusted_proxy_header` | The header those proxies report the client address in (default: `X-Forwarded-For`) |