You’ve been asked to stand up a Pritunl VPN for the company. The README walks you through dnf install pritunl, you start the service, the web UI works, you hand it over. Six months later, MongoDB is exposed on port 27017 because the bind IP took its default, fail2ban was never installed, SELinux drifted to permissive after a reboot, and the VPN — which was supposed to be the security boundary — is the weakest VM in the fleet.
What’s happening
A Pritunl deployment that is actually production-ready needs more than the package install. MongoDB has to be bound to 127.0.0.1 only (Pritunl talks to it locally); SELinux has to be enforcing on every reboot; fail2ban has to protect SSH; automatic security updates have to run on a schedule; the kernel has to be tuned for tunnel throughput (BBR plus IP forwarding matter materially under load); and SSH itself needs password auth disabled while preserving root key access for whoever owns the VM. None of these are individually critical. They compound — skip them and the VPN becomes the easiest entry point on the network.
How to verify
After install, the listeners should look like this:
ss -lntp | grep -E ':(443|27017)\b'
# 127.0.0.1:27017 mongod
# 0.0.0.0:443 pritunl-web
MongoDB on 27017 must be 127.0.0.1, never 0.0.0.0. SELinux must report Enforcing:
getenforce
SSH effective config (the live state, not just what’s in the file):
sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication)'
# permitrootlogin prohibit-password
# passwordauthentication no
# pubkeyauthentication yes
If any of those three drift, the security posture is gone — the rest of the stack assumes them.
The fix
Save the script below as /root/setup-pritunl-almalinux8.sh, then run it. It performs the full installer flow on a fresh AlmaLinux 8.x VM: base update + EPEL, kernel/network tuning (BBR, IP forwarding, syncookies, conservative redirects), file limits, removes firewalld in favour of Pritunl’s own iptables management, hardens SSH while keeping the root key, configures fail2ban for the SSH jail, enables dnf-automatic.timer for security updates, installs MongoDB 7.0 + Pritunl + WireGuard tools, writes a localhost-only mongod.conf, raises LimitNOFILE to 64000 on both services, starts everything in order, and waits for each listener to come up before continuing.
#!/usr/bin/env bash
set -euo pipefail
### AlmaLinux 8.x Pritunl clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs and configures MongoDB + Pritunl
### No local backups; assumes VM-level backup
### Reboot remains manual
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
echo
echo "========================================"
echo "Pritunl AlmaLinux 8.x Setup"
echo "========================================"
echo
echo "==> Updating base OS"
dnf -y update
dnf -y install epel-release
dnf -y update
echo "==> Installing base packages"
dnf -y install \
vim \
curl \
wget \
ca-certificates \
gnupg2 \
chrony \
fail2ban \
dnf-automatic \
policycoreutils-python-utils \
lsof \
tcpdump \
bind-utils \
yum-utils \
tar \
gzip \
unzip \
iproute \
net-tools
echo "==> Enabling time sync"
systemctl enable --now chronyd
timedatectl set-ntp true
echo "==> Configuring SELinux to enforcing on next boot"
if [[ -f /etc/selinux/config ]]; then
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
fi
if command -v getenforce >/dev/null 2>&1; then
CURRENT_SELINUX="$(getenforce || true)"
if [[ "$CURRENT_SELINUX" == "Disabled" ]]; then
echo "SELinux is currently disabled. It will require reboot to become enforcing."
else
setenforce 1 || true
fi
fi
echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-pritunl.conf <<'SYSCTL'
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL
modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
echo "==> Setting file limits"
cat > /etc/security/limits.d/99-pritunl.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS
echo "==> Disabling firewalld and iptables-services"
dnf -y remove iptables-services || true
systemctl stop firewalld || true
systemctl disable firewalld || true
systemctl mask firewalld || true
echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1"
local value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart sshd
echo "==> Configuring fail2ban for SSH"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Configuring automatic security updates"
cat > /etc/dnf/automatic.conf <<'DNFAUTO'
[commands]
upgrade_type = security
random_sleep = 900
network_online_timeout = 60
download_updates = yes
apply_updates = yes
[emitters]
emit_via = stdio
[base]
debuglevel = 1
DNFAUTO
systemctl enable --now dnf-automatic.timer
echo "==> Adding MongoDB repository"
cat > /etc/yum.repos.d/mongodb-org.repo <<'MONGO'
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-7.0.asc
MONGO
echo "==> Adding Pritunl repository"
cat > /etc/yum.repos.d/pritunl.repo <<'PRITUNL'
[pritunl]
name=Pritunl Repository
baseurl=https://repo.pritunl.com/stable/yum/oraclelinux/8/
gpgcheck=1
enabled=1
gpgkey=https://raw.githubusercontent.com/pritunl/pgp/master/pritunl_repo_pub.asc
PRITUNL
echo "==> Installing Pritunl, OpenVPN, WireGuard tools, MongoDB"
dnf clean all
dnf makecache
dnf -y install pritunl pritunl-openvpn wireguard-tools mongodb-org
echo "==> Writing clean MongoDB localhost-only config"
cp /etc/mongod.conf /etc/mongod.conf.bak.$(date +%F-%H%M%S) 2>/dev/null || true
cat > /etc/mongod.conf <<'MONGOD_CONF'
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
processManagement:
fork: false
pidFilePath: /var/run/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: 127.0.0.1
MONGOD_CONF
echo "==> Fixing MongoDB directories and permissions"
mkdir -p /var/lib/mongo /var/log/mongodb /var/run/mongodb
chown -R mongod:mongod /var/lib/mongo /var/log/mongodb /var/run/mongodb
chmod 755 /var/lib/mongo /var/log/mongodb /var/run/mongodb
echo "==> Writing Pritunl MongoDB URI"
mkdir -p /etc/pritunl
cat > /etc/pritunl.conf <<'PRITUNL_CONF'
{
"mongodb_uri": "mongodb://127.0.0.1:27017/pritunl"
}
PRITUNL_CONF
chmod 600 /etc/pritunl.conf
chown root:root /etc/pritunl.conf
echo "==> Setting systemd limits for Pritunl and MongoDB"
mkdir -p /etc/systemd/system/pritunl.service.d
cat > /etc/systemd/system/pritunl.service.d/override.conf <<'PRITUNL_LIMITS'
[Service]
LimitNOFILE=64000
PRITUNL_LIMITS
mkdir -p /etc/systemd/system/mongod.service.d
cat > /etc/systemd/system/mongod.service.d/override.conf <<'MONGO_LIMITS'
[Service]
LimitNOFILE=64000
MONGO_LIMITS
systemctl daemon-reload
echo "==> Enabling and starting MongoDB"
systemctl enable --now mongod
systemctl restart mongod
echo "==> Waiting for MongoDB to listen on localhost"
for i in {1..30}; do
if ss -lntp | grep -q '127.0.0.1:27017'; then
break
fi
sleep 1
done
if ! ss -lntp | grep -q '127.0.0.1:27017'; then
echo "MongoDB failed to listen on 127.0.0.1:27017"
echo
systemctl status mongod --no-pager -l || true
echo
journalctl -u mongod -n 120 --no-pager || true
exit 1
fi
echo "==> Testing MongoDB"
mongosh --quiet --eval 'db.runCommand({ ping: 1 })'
echo "==> Enabling and starting Pritunl"
systemctl enable --now pritunl
systemctl restart pritunl
echo "==> Waiting for Pritunl web listener"
for i in {1..30}; do
if ss -lntp | grep -q ':443'; then
break
fi
sleep 1
done
echo "==> Final package update"
dnf -y update
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r
echo
echo "SELinux:"
if command -v getenforce >/dev/null 2>&1; then
getenforce || true
else
echo "getenforce not available"
fi
echo
echo "SSH effective settings:"
sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication|kbdinteractiveauthentication|challengeresponseauthentication) ' || true
echo
echo "MongoDB listening:"
ss -lntp | grep 27017 || true
echo
echo "Pritunl listeners:"
ss -lntp | grep -E ':(80|443)\b' || true
echo
echo "Services:"
systemctl is-active mongod pritunl chronyd fail2ban || true
echo
echo "Pritunl setup key:"
pritunl setup-key
echo
echo "Pritunl default password:"
pritunl default-password
echo
echo "Web UI:"
echo "https://YOUR_SERVER_IP/"
echo
echo "Final step:"
echo "reboot"
Make it executable and run it:
chmod 700 /root/setup-pritunl-almalinux8.sh
/root/setup-pritunl-almalinux8.sh
The script prints the Pritunl setup key and the default password at the end. Reboot once after first run so SELinux transitions from Disabled to Enforcing cleanly, then open https://YOUR_SERVER_IP/, paste the setup key, and complete the web wizard. The script intentionally does not configure host-level backups — the assumption is the VM has snapshot/backup at the cloud layer; on bare metal, add a restic or borgbackup step covering /var/lib/mongo and /etc/pritunl.conf.
Run the production Pritunl on a Stack Harbor-managed environment with monitoring, patching cadence, and Sev-1 escalation in place: Managed Cloud Ops →.