# Install Ntfy server on Debian linux.

##### The below guide is to install ntfy server on a self-hosted Debian linux.

#### 1. Install the Ntfy Server.

Go on the root folder

```bash
cd /root
```

##### Make the install script file

```bash
nano install-ntfy.sh
```

copy and paste the below code

```bash
#!/bin/bash

# Update package lists and upgrade existing packages
apt update && apt dist-upgrade -y

# Install required packages for HTTPS transport, curl, and GPG
apt install -y apt-transport-https curl gpg

# Create directory for GPG keyrings if it doesn't exist
mkdir -p /etc/apt/keyrings

# Download the public key and store it securely
curl -fsSL https://archive.heckel.io/apt/pubkey.txt | gpg --dearmor -o /etc/apt/keyrings/archive.heckel.io.gpg

# Add the repository to sources list if not already present
REPO_FILE="/etc/apt/sources.list.d/archive.heckel.io.list"
if [ ! -f "$REPO_FILE" ]; then
    echo 'deb [arch=amd64 signed-by=/etc/apt/keyrings/archive.heckel.io.gpg] https://archive.heckel.io/apt debian main' > "$REPO_FILE"
fi

# Update package lists again to include new repository
apt update

# Install ntfy from the repository
apt install -y ntfy

# Enable and start the ntfy systemd service for automatic startup
systemctl enable ntfy
systemctl start ntfy
```

Press `<strong> Ctrl + x </strong>` to save then press ` y ` and press ` enter `

##### Make the script executable

```bash
chmod +x install-ntfy.sh
```

Execute the install-ntfy.sh and install Ntfy Server

```bash
./install-ntfy.sh
```

#### Setting up Ntfy configuration

The ntfy config files, both for **server** and **clients** are store at ` <strong>/etc/ntfy </strong>`

Now go to that path

```bash
# Go to the ntfy directory
cd /etc/ntfy
# List the files inside the ntfy directory
ls -al
```

##### Configuring Ntfy Server

Before we continue with the server configuration yaml file, let's make a copy first of the example ` <strong>server.yml </strong>` then we will work the original file not the bak. We will keep ONLY the setting we need for now for make the server.yml simplier. If need extra configuration then check the server.yml.bak file that have all the settings and explanations for them.   
You can also check the documentation [https://push.greenhome.stream/docs/](https://push.greenhome.stream/docs/ "Ntfy Documantation")

```bash
# Make a backup copy of the orignal file server.yml
cp server.yml server.yml.bak
# Edit the server.yml file
nano server.yml
```

Press **` Ctrl + k `** and holded until you erase all line from the server.ym file.  
Copy and paste the below example setting and change them according to your needs.

```bash
## Base settings
base-url: "http://your-ip.or-domain.com"
listen-http: ":80"
# listen-https:
# key-file: <filename>
# cert-file: <filename>

## Auth settings
auth-file: /var/lib/ntfy/user.db
auth-default-access: "deny-all"
enable-signup: true
enable-login: true
# enable-reservations: false
# auth-startup-queries:

## Proxy
behind-proxy: true

## Cache file
cache-file: "/var/cache/ntfy/cache.db"
cache-duration: "24h"

## Cache attachment size
attachment-cache-dir: "/var/cache/ntfy/attachments"
attachment-total-size-limit: "5G"
attachment-file-size-limit: "150M"
attachment-expiry-duration: "24h"

## ios
upstream-base-url: "https://ntfy.sh"

## Logs settings
log-level: info
log-format: json
log-file: "/var/log/ntfy.log"
```

You have to create the `<strong> ntfy.log </strong>` file and give it permission of the ntfy user.

```bash
## Create the log file
touch /var/log/ntfy.log
## Assign permission to ntfy user
chown ntfy:ntfy /var/log/ntfy.log
```

Now you have to restart the ntfy service for the changes to be apply.

```bash
systemctl restart ntfy
```

Now go to your instance where is hosted ntfy server refresh the browser and you will up-right a Sign IN and Sign UP buttons, to sign up and start to make use of the ntfy.

##### Add users.

You can add user from the Web UI by sign up OR you can add user from the command cli of the host where ntfy is hosted.  
At the below example we add a user with a name `<strong> xristina </strong>`

```bash
ntfy user add xristina
```

And then it will prompt you to put the password for the user you want to add. This user is create like a **simple user** that means it can create topics but it can read/write topics only that user create. To have access to other topics so it can read or read/write them you must give his that access, check below Give access to user.

##### List users.

To list the users run the below command.

```bash
ntfy user list
```

##### Change the Role of a user.

You can change the role of a use from the command cli with the below commands.  
At the below example we change role to user `<strong> xristina </strong>` to be **` admin `**  
Roles are : admin, pro, user,

```bash
ntfy user change-role xristina admin
```

##### Give access to user for a topic to read or read/write.

At the below example we give access to user `<strong> xristina </strong>` to topic ` <strong>test</strong> `

```bash
ntsy access xristina test rw
```

<span style="color: rgb(224, 62, 45);">**Ins0mniA**</span>

<div class="notranslate" id="bkmrk--1" style="all: initial;"></div>