Title: Configuration - ntfy URL Source: https://docs.ntfy.sh/config Markdown Content: Configuring the ntfy server[¶](https://docs.ntfy.sh/config#configuring-the-ntfy-server "Permanent link") -------------------------------------------------------------------------------------------------------- The ntfy server can be configured in three ways: using a config file (typically at `/etc/ntfy/server.yml`, see [server.yml](https://github.com/binwiederhier/ntfy/blob/main/server/server.yml)), via command line arguments or using environment variables. Quick start[¶](https://docs.ntfy.sh/config#quick-start "Permanent link") ------------------------------------------------------------------------ By default, simply running `ntfy serve` will start the server at port 80. No configuration needed. Batteries included 😀. If everything works as it should, you'll see something like this: ``` $ ntfy serve 2021/11/30 19:59:08 Listening on :80 ``` You can immediately start [publishing messages](https://docs.ntfy.sh/publish/), or subscribe via the [Android app](https://docs.ntfy.sh/subscribe/phone/), [the web UI](https://docs.ntfy.sh/subscribe/web/), or simply via [curl or your favorite HTTP client](https://docs.ntfy.sh/subscribe/api/). To configure the server further, check out the [config options table](https://docs.ntfy.sh/config#config-options) or simply type `ntfy serve --help` to get a list of [command line options](https://docs.ntfy.sh/config#command-line-options). Example config[¶](https://docs.ntfy.sh/config#example-config "Permanent link") ------------------------------------------------------------------------------ Info Definitely check out the **[server.yml](https://github.com/binwiederhier/ntfy/blob/main/server/server.yml)** file. It contains examples and detailed descriptions of all the settings. You may also want to look at how ntfy.sh is configured in the [ntfy-ansible](https://github.com/binwiederhier/ntfy-ansible) repository. The most basic settings are `base-url` (the external URL of the ntfy server), the HTTP/HTTPS listen address (`listen-http` and `listen-https`), and socket path (`listen-unix`). All the other things are additional features. Here are a few working sample configs using a `/etc/ntfy/server.yml` file: server.yml (HTTP-only, with cache + attachments) server.yml (HTTP+HTTPS, with cache + attachments) server.yml (behind proxy, with cache + attachments) server.yml (ntfy.sh config) ``` base-url: "http://ntfy.example.com" cache-file: "/var/cache/ntfy/cache.db" attachment-cache-dir: "/var/cache/ntfy/attachments" ``` ``` base-url: "http://ntfy.example.com" listen-http: ":80" listen-https: ":443" key-file: "/etc/letsencrypt/live/ntfy.example.com.key" cert-file: "/etc/letsencrypt/live/ntfy.example.com.crt" cache-file: "/var/cache/ntfy/cache.db" attachment-cache-dir: "/var/cache/ntfy/attachments" ``` ``` base-url: "http://ntfy.example.com" listen-http: ":2586" cache-file: "/var/cache/ntfy/cache.db" attachment-cache-dir: "/var/cache/ntfy/attachments" behind-proxy: true ``` ``` # All the things: Behind a proxy, Firebase, cache, attachments, # SMTP publishing & receiving base-url: "https://ntfy.sh" listen-http: "127.0.0.1:2586" firebase-key-file: "/etc/ntfy/firebase.json" cache-file: "/var/cache/ntfy/cache.db" behind-proxy: true attachment-cache-dir: "/var/cache/ntfy/attachments" smtp-sender-addr: "email-smtp.us-east-2.amazonaws.com:587" smtp-sender-user: "AKIDEADBEEFAFFE12345" smtp-sender-pass: "Abd13Kf+sfAk2DzifjafldkThisIsNotARealKeyOMG." smtp-sender-from: "ntfy@ntfy.sh" smtp-server-listen: ":25" smtp-server-domain: "ntfy.sh" smtp-server-addr-prefix: "ntfy-" keepalive-interval: "45s" ``` Alternatively, you can also use command line arguments or environment variables to configure the server. Here's an example using Docker Compose (i.e. `docker-compose.yml`): Docker Compose (w/ auth, cache, attachments) Docker Compose (w/ auth, cache, web push, iOS) ``` services: ntfy: image: binwiederhier/ntfy restart: unless-stopped environment: NTFY_BASE_URL: http://ntfy.example.com NTFY_CACHE_FILE: /var/lib/ntfy/cache.db NTFY_AUTH_FILE: /var/lib/ntfy/auth.db NTFY_AUTH_DEFAULT_ACCESS: deny-all NTFY_AUTH_USERS: 'phil:$$2a$$10$$YLiO8U21sX1uhZamTLJXHuxgVC0Z/GKISibrKCLohPgtG7yIxSk4C:admin' # Must escape '$' as '$$' NTFY_BEHIND_PROXY: true NTFY_ATTACHMENT_CACHE_DIR: /var/lib/ntfy/attachments NTFY_ENABLE_LOGIN: true volumes: - ./:/var/lib/ntfy ports: - 80:80 command: serve ``` ``` services: ntfy: image: binwiederhier/ntfy restart: unless-stopped environment: NTFY_BASE_URL: http://ntfy.example.com NTFY_CACHE_FILE: /var/lib/ntfy/cache.db NTFY_AUTH_FILE: /var/lib/ntfy/auth.db NTFY_AUTH_DEFAULT_ACCESS: deny-all NTFY_BEHIND_PROXY: true NTFY_ATTACHMENT_CACHE_DIR: /var/lib/ntfy/attachments NTFY_ENABLE_LOGIN: true NTFY_UPSTREAM_BASE_URL: https://ntfy.sh NTFY_WEB_PUSH_PUBLIC_KEY: NTFY_WEB_PUSH_PRIVATE_KEY: NTFY_WEB_PUSH_FILE: /var/lib/ntfy/webpush.db NTFY_WEB_PUSH_EMAIL_ADDRESS: volumes: - ./:/var/lib/ntfy ports: - 8093:80 command: serve ``` Message cache[¶](https://docs.ntfy.sh/config#message-cache "Permanent link") ---------------------------------------------------------------------------- If desired, ntfy can temporarily keep notifications in an in-memory or an on-disk cache. Caching messages for a short period of time is important to allow [phones](https://docs.ntfy.sh/subscribe/phone/) and other devices with brittle Internet connections to be able to retrieve notifications that they may have missed. By default, ntfy keeps messages **in-memory for 12 hours**, which means that **cached messages do not survive an application restart**. You can override this behavior using the following config settings: * `cache-file`: if set, ntfy will store messages in a SQLite based cache (default is empty, which means in-memory cache). **This is required if you'd like messages to be retained across restarts**. * `cache-duration`: defines the duration for which messages are stored in the cache (default is `12h`). You can also entirely disable the cache by setting `cache-duration` to `0`. When the cache is disabled, messages are only passed on to the connected subscribers, but never stored on disk or even kept in memory longer than is needed to forward the message to the subscribers. Subscribers can retrieve cached messaging using the [`poll=1` parameter](https://docs.ntfy.sh/subscribe/api/#poll-for-messages), as well as the [`since=` parameter](https://docs.ntfy.sh/subscribe/api/#fetch-cached-messages). Attachments[¶](https://docs.ntfy.sh/config#attachments "Permanent link") ------------------------------------------------------------------------ If desired, you may allow users to upload and [attach files to notifications](https://docs.ntfy.sh/publish/#attachments). To enable this feature, you have to simply configure an attachment cache directory and a base URL (`attachment-cache-dir`, `base-url`). Once these options are set and the directory is writable by the server user, you can upload attachments via PUT. By default, attachments are stored in the disk-cache **for only 3 hours**. The main reason for this is to avoid legal issues and such when hosting user controlled content. Typically, this is more than enough time for the user (or the auto download feature) to download the file. The following config options are relevant to attachments: * `base-url` is the root URL for the ntfy server; this is needed for the generated attachment URLs * `attachment-cache-dir` is the cache directory for attached files * `attachment-total-size-limit` is the size limit of the on-disk attachment cache (default: 5G) * `attachment-file-size-limit` is the per-file attachment size limit (e.g. 300k, 2M, 100M, default: 15M) * `attachment-expiry-duration` is the duration after which uploaded attachments will be deleted (e.g. 3h, 20h, default: 3h) Here's an example config using mostly the defaults (except for the cache directory, which is empty by default): /etc/ntfy/server.yml (minimal) /etc/ntfy/server.yml (all options) ``` base-url: "https://ntfy.sh" attachment-cache-dir: "/var/cache/ntfy/attachments" ``` ``` base-url: "https://ntfy.sh" attachment-cache-dir: "/var/cache/ntfy/attachments" attachment-total-size-limit: "5G" attachment-file-size-limit: "15M" attachment-expiry-duration: "3h" visitor-attachment-total-size-limit: "100M" visitor-attachment-daily-bandwidth-limit: "500M" ``` Please also refer to the [rate limiting](https://docs.ntfy.sh/config#rate-limiting) settings below, specifically `visitor-attachment-total-size-limit` and `visitor-attachment-daily-bandwidth-limit`. Setting these conservatively is necessary to avoid abuse. Access control[¶](https://docs.ntfy.sh/config#access-control "Permanent link") ------------------------------------------------------------------------------ By default, the ntfy server is open for everyone, meaning **everyone can read and write to any topic** (this is how ntfy.sh is configured). To restrict access to your own server, you can optionally configure authentication and authorization. ntfy's auth is implemented with a simple [SQLite](https://www.sqlite.org/)-based backend. It implements two roles (`user` and `admin`) and per-topic `read` and `write` permissions using an [access control list (ACL)](https://en.wikipedia.org/wiki/Access-control_list). Access control entries can be applied to users as well as the special everyone user (`*`), which represents anonymous API access. To set up auth, **configure the following options**: * `auth-file` is the user/access database; it is created automatically if it doesn't already exist; suggested location `/var/lib/ntfy/user.db` (easiest if deb/rpm package is used) * `auth-default-access` defines the default/fallback access if no access control entry is found; it can be set to `read-write` (default), `read-only`, `write-only` or `deny-all`. **If you are setting up a private instance, you'll want to set this to `deny-all`** (see [private instance example](https://docs.ntfy.sh/config#example-private-instance)). Once configured, you can use * the `ntfy user` command and the `auth-users` config option to [add or modify users](https://docs.ntfy.sh/config#users-and-roles) * the `ntfy access` command and the `auth-access` option to [modify the access control list](https://docs.ntfy.sh/config#access-control-list-acl) and topic patterns, and * the `ntfy token` command and the `auth-tokens` config option to [manage access tokens](https://docs.ntfy.sh/config#access-tokens) for users. These commands **directly edit the auth database** (as defined in `auth-file`), so they only work on the server, and only if the user accessing them has the right permissions. ### Users and roles[¶](https://docs.ntfy.sh/config#users-and-roles "Permanent link") Users can be added to the ntfy user database in two different ways * [Using the CLI](https://docs.ntfy.sh/config#users-via-the-cli): Using the `ntfy user` command, you can manually add/update/remove users. * [In the config](https://docs.ntfy.sh/config#users-via-the-config): You can provision users in the `server.yml` file via `auth-users` key. #### Users via the CLI[¶](https://docs.ntfy.sh/config#users-via-the-cli "Permanent link") The `ntfy user` command allows you to add/remove/change users in the ntfy user database, as well as change passwords or roles (`user` or `admin`). In practice, you'll often just create one admin user with `ntfy user add --role=admin ...` and be done with all this (see [example below](https://docs.ntfy.sh/config#example-private-instance)). **Roles:** * Role `user` (default): Users with this role have no special permissions. Manage access using `ntfy access` (see [below](https://docs.ntfy.sh/config#access-control-list-acl)). * Role `admin`: Users with this role can read/write to all topics. Granular access control is not necessary. **Example commands** (type `ntfy user --help` or `ntfy user COMMAND --help` for more details): ``` ntfy user list # Shows list of users (alias: 'ntfy access') ntfy user add phil # Add regular user phil ntfy user add --role=admin phil # Add admin user phil ntfy user del phil # Delete user phil ntfy user change-pass phil # Change password for user phil ntfy user change-role phil admin # Make user phil an admin ntfy user change-tier phil pro # Change phil's tier to "pro" ntfy user hash # Generate password hash, use with auth-users config option ``` #### Users via the config[¶](https://docs.ntfy.sh/config#users-via-the-config "Permanent link") As an alternative to manually creating users via the `ntfy user` CLI command, you can provision users declaratively in the `server.yml` file by adding them to the `auth-users` array. This is useful for general admins, or if you'd like to deploy your ntfy server via Docker/Ansible without manually editing the database. The `auth-users` option is a list of users that are automatically created/updated when the server starts. Users previously defined in the config but later removed will be deleted. Each entry is defined in the format `::`. Here's an example with two users: `phil` is an admin, `ben` is a regular user. Declarative users in /etc/ntfy/server.yml Declarative users via env variables ``` auth-file: "/var/lib/ntfy/user.db" auth-users: - "phil:$2a$10$YLiO8U21sX1uhZamTLJXHuxgVC0Z/GKISibrKCLohPgtG7yIxSk4C:admin" - "ben:$2a$10$NKbrNb7HPMjtQXWJ0f1pouw03LDLT/WzlO9VAv44x84bRCkh19h6m:user" ``` ``` # Comma-separated list, use single quotes to avoid issues with the bcrypt hash NTFY_AUTH_FILE='/var/lib/ntfy/user.db' NTFY_AUTH_USERS='phil:$2a$10$YLiO8U21sX1uhZamTLJXHuxgVC0Z/GKISibrKCLohPgtG7yIxSk4C:admin,ben:$2a$10$NKbrNb7HPMjtQXWJ0f1pouw03LDLT/WzlO9VAv44x84bRCkh19h6m:user' ``` The password hash can be created using `ntfy user hash` or an [online bcrypt generator](https://bcrypt-generator.com/) (though note that you're putting your password in an untrusted website). Important Users added declaratively via the config file are marked in the database as "provisioned users". Removing users from the config file will **delete them from the database** the next time ntfy is restarted. Also, users that were originally manually created will be "upgraded" to be provisioned users if they are added to the config. Adding a user manually, then adding it to the config, and then removing it from the config will hence lead to the **deletion of that user**. ### Access control list (ACL)[¶](https://docs.ntfy.sh/config#access-control-list-acl "Permanent link") The access control list (ACL) **manages access to topics for non-admin users, and for anonymous access (`everyone`/`*`)**. Each entry represents the access permissions for a user to a specific topic or topic pattern. Entries can be created in two different ways: * [Using the CLI](https://docs.ntfy.sh/config#acl-entries-via-the-cli): Using the `ntfy access` command, you can manually edit the access control list. * [In the config](https://docs.ntfy.sh/config#acl-entries-via-the-config): You can provision ACL entries in the `server.yml` file via `auth-access` key. #### ACL entries via the CLI[¶](https://docs.ntfy.sh/config#acl-entries-via-the-cli "Permanent link") The ACL can be displayed or modified with the `ntfy access` command: ``` ntfy access # Shows access control list (alias: 'ntfy user list') ntfy access USERNAME # Shows access control entries for USERNAME ntfy access USERNAME TOPIC PERMISSION # Allow/deny access for USERNAME to TOPIC ``` A `USERNAME` is an existing user, as created with `ntfy user add` (see [users and roles](https://docs.ntfy.sh/config#users-and-roles)), or the anonymous user `everyone` or `*`, which represents clients that access the API without username/password. A `TOPIC` is either a specific topic name (e.g. `mytopic`, or `phil_alerts`), or a wildcard pattern that matches any number of topics (e.g. `alerts_*` or `ben-*`). Only the wildcard character `*` is supported. It stands for zero to any number of characters. A `PERMISSION` is any of the following supported permissions: * `read-write` (alias: `rw`): Allows [publishing messages](https://docs.ntfy.sh/publish/) to the given topic, as well as [subscribing](https://docs.ntfy.sh/subscribe/api/) and reading messages * `read-only` (aliases: `read`, `ro`): Allows only subscribing and reading messages, but not publishing to the topic * `write-only` (aliases: `write`, `wo`): Allows only publishing to the topic, but not subscribing to it * `deny` (alias: `none`): Allows neither publishing nor subscribing to a topic **Example commands** (type `ntfy access --help` for more details): ``` ntfy access # Shows entire access control list ntfy access phil # Shows access for user phil ntfy access phil mytopic rw # Allow read-write access to mytopic for user phil ntfy access everyone mytopic rw # Allow anonymous read-write access to mytopic ntfy access everyone "up*" write # Allow anonymous write-only access to topics "up..." ntfy access --reset # Reset entire access control list ntfy access --reset phil # Reset all access for user phil ntfy access --reset phil mytopic # Reset access for user phil and topic mytopic ``` **Example ACL:** ``` $ ntfy access user phil (admin) - read-write access to all topics (admin role) user ben (user) - read-write access to topic garagedoor - read-write access to topic alerts* - read-only access to topic furnace user * (anonymous) - read-only access to topic announcements - read-only access to topic server-stats - no access to any (other) topics (server config) ``` In this example, `phil` has the role `admin`, so he has read-write access to all topics (no ACL entries are necessary). User `ben` has three topic-specific entries. He can read, but not write to topic `furnace`, and has read-write access to topic `garagedoor` and all topics starting with the word `alerts` (wildcards). Clients that are not authenticated (called `*`/`everyone`) only have read access to the `announcements` and `server-stats` topics. #### ACL entries via the config[¶](https://docs.ntfy.sh/config#acl-entries-via-the-config "Permanent link") As an alternative to manually creating ACL entries via the `ntfy access` CLI command, you can provision access control entries declaratively in the `server.yml` file by adding them to the `auth-access` array, similar to the `auth-users` option (see [users via the config](https://docs.ntfy.sh/config#users-via-the-config). The `auth-access` option is a list of access control entries that are automatically created/updated when the server starts. When entries are removed, they are deleted from the database. Each entry is defined in the format `::`. The `` can be any existing, provisioned user as defined in the `auth-users` section (see [users via the config](https://docs.ntfy.sh/config#users-via-the-config)), or `everyone`/`*` for anonymous access. The `` can be a specific topic name or a pattern with wildcards (`*`). The `` can be one of the following: * `read-write` or `rw`: Allows both publishing to and subscribing to the topic * `read-only`, `read`, or `ro`: Allows only subscribing to the topic * `write-only`, `write`, or `wo`: Allows only publishing to the topic * `deny-all`, `deny`, or `none`: Denies all access to the topic Here's an example with several ACL entries: Declarative ACL entries in /etc/ntfy/server.yml Declarative ACL entries via env variables ``` auth-file: "/var/lib/ntfy/user.db" auth-users: - "phil:$2a$10$YLiO8U21sX1uhZamTLJXHuxgVC0Z/GKISibrKCLohPgtG7yIxSk4C:user" - "ben:$2a$10$NKbrNb7HPMjtQXWJ0f1pouw03LDLT/WzlO9VAv44x84bRCkh19h6m:user" auth-access: - "phil:mytopic:rw" - "ben:alerts-*:rw" - "ben:system-logs:ro" - "*:announcements:ro" # or: "everyone:announcements,ro" ``` ``` # Comma-separated list NTFY_AUTH_FILE='/var/lib/ntfy/user.db' NTFY_AUTH_USERS='phil:$2a$10$YLiO8U21sX1uhZamTLJXHuxgVC0Z/GKISibrKCLohPgtG7yIxSk4C:user,ben:$2a$10$NKbrNb7HPMjtQXWJ0f1pouw03LDLT/WzlO9VAv44x84bRCkh19h6m:user' NTFY_AUTH_ACCESS='phil:mytopic:rw,ben:alerts-*:rw,ben:system-logs:ro,*:announcements:ro' ``` In this example, the `auth-users` section defines two users, `phil` and `ben`. The `auth-access` section defines access control entries for these users. `phil` has read-write access to the topic `mytopic`, while `ben` has read-write access to all topics starting with `alerts-` and read-only access to the topic `system-logs`. The last entry allows anonymous users (i.e. clients that do not authenticate) to read the `announcements` topic. ### Access tokens[¶](https://docs.ntfy.sh/config#access-tokens "Permanent link") In addition to username/password auth, ntfy also provides authentication via access tokens. Access tokens are useful to avoid having to configure your password across multiple publishing/subscribing applications. For instance, you may want to use a dedicated token to publish from your backup host, and one from your home automation system. Info As of today, access tokens grant users **full access to the user account**. Aside from changing the password, and deleting the account, every action can be performed with a token. Granular access tokens are on the roadmap, but not yet implemented. You can create access tokens in two different ways: * [Using the CLI](https://docs.ntfy.sh/config#tokens-via-the-cli): Using the `ntfy token` command, you can manually add/update/remove tokens. * [In the config](https://docs.ntfy.sh/config#tokens-via-the-config): You can provision access tokens in the `server.yml` file via `auth-tokens` key. #### Tokens via the CLI[¶](https://docs.ntfy.sh/config#tokens-via-the-cli "Permanent link") The `ntfy token` command can be used to manage access tokens for users. Tokens can have labels, and they can expire automatically (or never expire). Each user can have up to 60 tokens (hardcoded). **Example commands** (type `ntfy token --help` or `ntfy token COMMAND --help` for more details): ``` ntfy token list # Shows list of tokens for all users ntfy token list phil # Shows list of tokens for user phil ntfy token add phil # Create token for user phil which never expires ntfy token add --expires=2d phil # Create token for user phil which expires in 2 days ntfy token remove phil tk_th2sxr... # Delete token ntfy token generate # Generate random token, can be used in auth-tokens config option ``` **Creating an access token:** ``` $ ntfy token add --expires=30d --label="backups" phil $ ntfy token list user phil - tk_7eevizlsiwf9yi4uxsrs83r4352o0 (backups), expires 15 Mar 23 14:33 EDT, accessed from 0.0.0.0 at 13 Feb 23 13:33 EST ``` Once an access token is created, you can **use it to authenticate against the ntfy server, e.g. when you publish or subscribe to topics**. To learn how, check out [authenticate via access tokens](https://docs.ntfy.sh/publish/#access-tokens). #### Tokens via the config[¶](https://docs.ntfy.sh/config#tokens-via-the-config "Permanent link") Access tokens can be pre-provisioned in the `server.yml` configuration file using the `auth-tokens` config option. This is useful for automated setups, Docker environments, or when you want to define tokens declaratively. The `auth-tokens` option is a list of access tokens that are automatically created/updated when the server starts. When entries are removed, they are deleted from the database. Each entry is defined in the format `:[: