Installing Authentik on VPS: SSO, MFA, and Centralized Authentication
TL;DR
In this detailed guide, we will step-by-step configure Authentik — a powerful Open Source Identity and Access Management (IAM) solution on your own VPS. You will get a centralized Single Sign-On (SSO) and Multi-Factor Authentication (MFA) system, ready for integration with your web applications, which will significantly enhance security and simplify user management.
- Authentik will be installed using Docker Compose for easy deployment and management.
- An external PostgreSQL 16 database will be used for better performance and scalability.
- We will configure Caddy as a reverse proxy with automatic TLS/HTTPS certificate acquisition from Let's Encrypt.
- Basic server security steps, including firewall and SSH keys, will be covered.
- You will learn how to set up backups and keep the system up to date.
What we are configuring and why
In the modern digital world, managing user accounts and ensuring their secure access to multiple applications has become a critically important task. Authentik offers an elegant and powerful solution to this problem, acting as a centralized identity provider.
Authentik is an Open Source Identity and Access Management (IAM) platform that enables Single Sign-On (SSO) and Multi-Factor Authentication (MFA) for all your applications. Instead of creating and managing separate accounts for each service (GitLab, Mattermost, Nextcloud, Grafana, etc.), users will authenticate once through Authentik and then gain seamless access to all integrated applications.
Ultimately, upon completing this guide, you will have a fully configured Authentik system on your VPS, which will serve as a central authentication point. This will significantly enhance security through enforced MFA and centralized password management, as well as improve user experience by eliminating the need to remember multiple logins and passwords.
There are various approaches to solving IAM tasks. Among cloud-managed services, Okta, Auth0, or Azure AD offer high availability and minimal administration costs, but they require monthly payments and imply transferring control over data to a third party. On the other hand, there are other self-hosted solutions such as Keycloak or FreeIPA, which also provide SSO and MFA capabilities but can be more complex to deploy and configure compared to Authentik, especially for small and medium-sized installations.
The choice of a self-hosted solution on a VPS, such as Authentik, is driven by several key advantages. Firstly, it provides full control over your data and infrastructure, which is especially important for privacy and regulatory compliance. Secondly, it offers significant cost savings compared to cloud counterparts, especially in the long term. And finally, it provides flexibility and the ability for deep customization to meet your unique needs, making it an ideal choice for developers, solo SaaS founders, and anyone who values independence and security.
What VPS configuration is needed for this task
The correct choice of VPS configuration is key to the stable and productive operation of Authentik. Below are the minimum and recommended requirements, current for 2026, taking into account the growth of Authentik's functionality and optimization.
Minimum requirements (for small teams up to 50 users)
- CPU: 2 vCPU (modern x86-64 processor, e.g., Intel Xeon E3/E5 or AMD EPYC).
- RAM: 4 GB (sufficient for the operating system, Authentik, and PostgreSQL).
- Disk: 80-100 GB NVMe SSD. Disk subsystem speed is critical for database performance and overall system responsiveness. NVMe significantly outperforms standard SATA SSDs.
- Network: 1 Gbit/s uplink. A public IPv4 address is mandatory for accessing Authentik from the internet.
Recommended VPS plan (for teams up to 200-300 users)
For more comfortable operation, with room for scaling and integrating several dozen applications, the following configuration is recommended:
- CPU: 4 vCPU.
- RAM: 8 GB.
- Disk: 160-200 GB NVMe SSD.
- Network: 1 Gbit/s uplink, public IPv4.
To rent a VPS with the specified characteristics, you can consider offers from various providers that match these parameters. Make sure the chosen plan includes NVMe SSD and sufficient RAM.
When a dedicated server is needed, not a VPS
While a VPS is an excellent choice for most scenarios, there are situations where a dedicated server would be more preferable:
- Very high load: If you expect thousands of active users, hundreds of authentication requests per second, or integration with critical enterprise systems, a dedicated server will provide you with the full power of physical hardware without virtualization.
- Strict performance requirements: For applications where even millisecond latency is critical, a dedicated server can offer more predictable and stable performance.
- Specific security/compliance requirements: Some regulatory norms or internal company policies may require full control over hardware, which is best achieved on a dedicated server.
- Large data volumes: If Authentik will store significant amounts of user data, logs, or integrate with very large directories, the larger disk subsystem of a dedicated server will be beneficial.
VPS location: what it affects
Choosing the geographical location of your VPS has several important aspects:
- Latency: Place the VPS as close as possible to the majority of your users. The shorter the distance, the faster the server responses will be, which is critical for interactive web applications and overall user experience.
- Data legislation: If you are working with personal data, ensure that the VPS location complies with GDPR, HIPAA, or other local data storage and processing laws.
- Network availability: Choose locations with good network connections and peering with major providers to ensure stable and fast access.
Server preparation
Before proceeding with Authentik installation, you need to perform basic configuration of your VPS to ensure security and stability. We will use Ubuntu Server 24.04 LTS as the operating system, as it is one of the most popular and well-supported platforms for servers.
1. Connecting to the server
Connect to your VPS via SSH using the credentials provided by your provider (usually root login and password, or a user with an SSH key).
ssh root@ВАШ_IP_АДРЕС
2. System update
First, update all packages to their latest versions. This will ensure system security and stability.
sudo apt update && sudo apt upgrade -y
3. Creating a new user and configuring sudo
Working as the root user is not recommended for everyday tasks. Create a new user with limited privileges and add them to the sudo group.
# Replace 'youruser' with your desired username
sudo adduser youruser
sudo usermod -aG sudo youruser
Exit the root session and log in as the new user:
exit
ssh youruser@ВАШ_IP_АДРЕС
4. Configuring SSH key access (recommended)
For increased security, it is recommended to use SSH keys instead of passwords. If you already use keys, make sure your public key is added to the ~/.ssh/authorized_keys file of the new user.
On your local machine:
# If you don't have an SSH key, generate one
ssh-keygen -t rsa -b 4096
# Copy the public key to the server (replace youruser and ВАШ_IP_АДРЕС)
ssh-copy-id youruser@ВАШ_IP_АДРЕС
On the server: disable password login and for the root user.
sudo nano /etc/ssh/sshd_config
Find and change the following lines (or add them if they are missing):
# Disable root login
PermitRootLogin no
# Disable password authentication (after you ensure key login works!)
PasswordAuthentication no
# Make sure key authentication is enabled
PubkeyAuthentication yes
Restart the SSH service:
sudo systemctl restart sshd
5. Installing and configuring Fail2Ban
Fail2Ban helps protect against brute-force attacks by blocking IP addresses from which numerous failed login attempts occur.
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
Create a local configuration file:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
In the [DEFAULT] section, you can set more aggressive parameters, for example:
bantime = 1h # Ban time (1 hour)
findtime = 10m # Time window for attempts (10 minutes)
maxretry = 3 # Maximum number of attempts before banning
Ensure that the [sshd] section is active (enabled = true).
sudo systemctl restart fail2ban
6. Configuring the firewall (UFW)
UFW (Uncomplicated Firewall) is a convenient interface for managing iptables. We will configure it to allow only necessary traffic.
sudo apt install ufw -y
# Deny all incoming traffic by default
sudo ufw default deny incoming
# Allow all outgoing traffic by default
sudo ufw default allow outgoing
# Allow SSH (default port 22)
sudo ufw allow ssh
# Allow HTTP (port 80) and HTTPS (port 443) for the web server
sudo ufw allow http
sudo ufw allow https
# Enable UFW
sudo ufw enable
Confirm the action by typing y. Check the firewall status:
sudo ufw status verbose
7. Installing basic utilities
Install several useful utilities that may come in handy during the installation and debugging process.
sudo apt install curl wget git htop net-tools -y
Now your server is prepared and secured for further Authentik deployment.
Software Installation — Step-by-Step
Authentik is deployed using Docker Compose, which significantly simplifies the management of its components. We will also use an external PostgreSQL database for better performance and scalability.
1. Installing Docker Engine and Docker Compose Plugin (relevant for 2026)
We will install Docker Engine and Docker Compose Plugin, which are essential for running Authentik.
# 1. Update packages and install necessary dependencies
sudo apt update && sudo apt install ca-certificates curl gnupg lsb-release -y
# 2. Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 3. Add Docker repository
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 4. Update APT package index and install Docker Engine
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
# 5. Add current user to the docker group to execute commands without sudo
sudo usermod -aG docker $USER
newgrp docker # Apply group changes without restarting the session
# 6. Verify Docker installation
docker run hello-world
# 7. Verify Docker Compose Plugin installation
docker compose version
The expected output for Docker Compose version will be approximately Docker Compose version v2.24.x or higher.
2. Installing and Configuring PostgreSQL 16
Authentik uses a database to store its data. Instead of using the built-in database in a Docker container, we will install PostgreSQL 16 directly on the VPS for better performance and manageability.
# 1. Install PostgreSQL 16
sudo apt install postgresql-16 -y
# 2. Start and enable PostgreSQL
sudo systemctl enable postgresql
sudo systemctl start postgresql
# 3. Switch to postgres user for database configuration
sudo -i -u postgres
# 4. Create a new database and user for Authentik
psql -c "CREATE DATABASE authentik;"
psql -c "CREATE USER authentik_user WITH PASSWORD 'ВАШ_ОЧЕНЬ_СИЛЬНЫЙ_ПАРОЛЬ_ДЛЯ_БД';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE authentik TO authentik_user;"
# 5. Exit postgres user
exit
Replace 'ВАШ_ОЧЕНЬ_СИЛЬНЫЙ_ПАРОЛЬ_ДЛЯ_БД' with a strong unique password. Record it, as it will be needed for Authentik configuration.
3. Deploying Authentik with Docker Compose
Now we are ready to deploy Authentik using its official Docker images.
# 1. Create a directory for Authentik and navigate into it
mkdir ~/authentik
cd ~/authentik
# 2. Download docker-compose.yml and .env files from the official Authentik repository
# For example, we use the current version for 2024, which will also be relevant for 2026 with minor updates
# Always check the current URL on the official Authentik website (goauthentik.io)
wget https://goauthentik.io/docker-compose.yml
wget https://goauthentik.io/docker-compose.env
mv docker-compose.env .env # Rename the .env file
# 3. Generate a unique secret key for Authentik
# This key is used for data encryption and must be strong.
# Replace it with your generated key.
AUTHENTIK_SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_urlsafe(64))')
echo "AUTHENTIK_SECRET_KEY=$AUTHENTIK_SECRET_KEY" >> .env
echo "Authentik secret key generated and added to .env"
Important: ensure that you are using the latest versions of docker-compose.yml and .env files from the official Authentik website. The commands above use public links, but there might be changes in 2026.
4. Configuring the .env file
Edit the .env file so that Authentik can connect to your external PostgreSQL database and use the correct domain.
nano .env
Find the following lines and modify them according to your configuration:
AUTHENTIK_HOST=https://your.domain.com/: Replaceyour.domain.comwith your actual domain name through which Authentik will be accessible.AUTHENTIK_POSTGRESQL__HOST=localhost: Indicates that PostgreSQL is on the same server.AUTHENTIK_POSTGRESQL__NAME=authentik: The name of the database we created.AUTHENTIK_POSTGRESQL__USER=authentik_user: The database username.AUTHENTIK_POSTGRESQL__PASSWORD=ВАШ_ОЧЕНЬ_СИЛЬНЫЙ_ПАРОЛЬ_ДЛЯ_БД: The database user's password.AUTHENTIK_REDIS__HOST=redis: Leave as is if you are using Docker Compose's internal Redis.
Example of edited lines in .env:
AUTHENTIK_HOST=https://auth.example.com/ # Your domain name
AUTHENTIK_SECRET_KEY=ВАШ_СГЕНЕРИРОВАННЫЙ_КЛЮЧ # It should already be there
AUTHENTIK_POSTGRESQL__HOST=localhost
AUTHENTIK_POSTGRESQL__NAME=authentik
AUTHENTIK_POSTGRESQL__USER=authentik_user
AUTHENTIK_POSTGRESQL__PASSWORD=ВАШ_ОЧЕНЬ_СИЛЬНЫЙ_ПАРОЛЬ_ДЛЯ_БД
AUTHENTIK_REDIS__HOST=redis
Save changes (Ctrl+O, Enter, Ctrl+X).
5. Starting Authentik
Now that everything is configured, start Authentik using Docker Compose.
# Download Docker images
docker compose pull
# Start Authentik containers in the background
docker compose up -d
Check the status of running containers:
docker compose ps
You should see authentik_server, authentik_worker, and redis containers in running status.
6. Creating an Authentik Superuser
To log into Authentik for the first time, you need to create a superuser account.
docker compose exec authentik sh -c "python3 manage.py createsuperuser"
Follow the instructions in the terminal to create an admin user (or any other name) and set a strong password for it. Record these credentials.
At this step, Authentik is installed and running. Next, we will configure access to it via the web interface using a reverse proxy and HTTPS.