Set up a Valheim dedicated server on a VPS with automated backups and mod management
Servidores de jogos · By Kevin Marcondes · Published on · Updated on · 8 min read
Want to host your own Valheim server on a VPS with security, automatic backups and mod support? This guide shows how to set up a dedicated Valheim server on a VPS, configure the firewall, automate backups, and install mods with BepInEx — step by step with ready-to-copy commands.
1. Prerequisites and VPS planning
You need an up-to-date Linux VPS (Ubuntu or Debian) and a user with sudo privileges. These steps require root/sudo access. Plan your data directories, backup retention and task schedules.
Helpful recommendations:
- System: up-to-date Ubuntu/Debian with sudo
- UDP ports 2456–2458 open in the firewall and at the provider panel
- Disk space for worlds and backups
- Server name, world name, port and a strong password defined
- Choose a VPS size proportional to the number of players and mods. See criteria in how to choose the right VPS size.
- Have the base OS ready. If needed, follow how to install Ubuntu Server.
- Note the world name, server name, port and password. Use a strong password.
- Only open the ports you need. If using UFW, see how to set up a firewall on Ubuntu with UFW.
2. Install dependencies and SteamCMD on Linux
Install SteamCMD and required utilities. On some distributions you must enable i386 architecture. Create a dedicated user to isolate the service and server directory.
sudo apt update
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install -y steamcmd lib32gcc-s1 unzip
# Usuário dedicado e diretório do servidor
sudo useradd -r -m -d /home/steam -s /bin/bash steam || true
sudo mkdir -p /opt/valheim
sudo chown -R steam:steam /opt/valheim
3. Download and organize the Valheim dedicated server
Use SteamCMD to download the dedicated server. Then create a startup script with Valheim options and point the saves directory to a separate path (makes backups easier). Change the password in the script before starting.
Directory layout example:
| Path | Description |
|---|---|
| /opt/valheim | Valheim server binaries |
| /opt/valheim/data | Worlds and saves (set by -savedir) |
| /opt/valheim/BepInEx | Mods and configs (after installing BepInEx) |
| /opt/valheim/backups | .tgz backup files |
| /etc/systemd/system/valheim.service | Server systemd service |
# Baixar/atualizar servidor dedicado (AppID 896660)
sudo -u steam /usr/games/steamcmd +login anonymous \
+force_install_dir /opt/valheim \
+app_update 896660 validate +quit
# Script de inicialização
sudo -u steam bash -lc 'cat > /opt/valheim/start.sh <<"EOF"
#!/bin/bash
set -euo pipefail
export LD_LIBRARY_PATH=/opt/valheim/linux64:$LD_LIBRARY_PATH
export SteamAppId=892970
NAME="Servidor Valheim"
WORLD="mundo1"
PASSWORD="TroqueEstaSenha"
PORT=2456
SAVEDIR="/opt/valheim/data"
mkdir -p "$SAVEDIR"
cd /opt/valheim
./valheim_server.x86_64 -name "$NAME" -port $PORT -world "$WORLD" -password "$PASSWORD" -savedir "$SAVEDIR" -public 1
EOF'
sudo chmod +x /opt/valheim/start.sh
sudo chown steam:steam /opt/valheim/start.sh
4. Create a systemd service to start automatically
Create a systemd service to start the server at boot, restart on failures and make management easier. Keep the service name to check logs later.
sudo bash -c 'cat > /etc/systemd/system/valheim.service <<"EOF"
[Unit]
Description=Valheim Dedicated Server
After=network-online.target
Wants=network-online.target
[Service]
User=steam
Group=steam
WorkingDirectory=/opt/valheim
ExecStart=/opt/valheim/start.sh
Restart=on-failure
RestartSec=15
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target
EOF'
sudo systemctl daemon-reload
sudo systemctl enable --now valheim
sudo systemctl status --no-pager valheim || true
5. Open the firewall and test connectivity
Allow Valheim's default ports (UDP 2456–2458). Then verify the server is listening and check the service logs. If the VPS is behind NAT, adjust provider-side port forwarding.
How to confirm it worked: open Valheim on the client and connect using the VPS public IP and port 2456. If it doesn't appear, try "Connect to IP" manually.
- If you use a firewall other than UFW, replicate these rules accordingly.
- Ports must be UDP. TCP is not required on 2456–2458.
- Verify the password meets the game's requirements.
# UFW (Ubuntu)
sudo ufw allow 2456:2458/udp
sudo ufw reload
# Checar porta e logs
sudo ss -lunp | grep 2456 || true
sudo journalctl -u valheim -n 50 --no-pager
6. Automated backups with rotation (local and optional cloud)
Create a script that compresses the worlds and removes old backups. Then use a systemd timer to run backups periodically. Testing restores is an essential part of backup strategy. For offsite copies add a cloud sync step (e.g., AWS CLI) according to your account.
- Set retention according to your play frequency.
- Store backups on a separate disk when possible.
- For offsite storage, add encrypted sync to a bucket.
# Pastas e script
sudo install -d -o steam -g steam /opt/valheim/scripts /opt/valheim/backups
sudo tee /opt/valheim/scripts/backup.sh >/dev/null <<'EOF'
#!/bin/bash
set -euo pipefail
SAVEDIR="/opt/valheim/data"
DEST="/opt/valheim/backups"
RETENTION_DAYS=7
TS=$(date +%F-%H%M)
mkdir -p "$DEST"
# Arquiva somente os dados do mundo
tar -czf "$DEST/world-$TS.tgz" -C "$SAVEDIR" .
# Remove backups antigos conforme retenção
find "$DEST" -type f -name "world-*.tgz" -mtime +$RETENTION_DAYS -delete
EOF
sudo chmod +x /opt/valheim/scripts/backup.sh
# Unidade e timer do systemd
sudo tee /etc/systemd/system/valheim-backup.service >/dev/null <<'EOF'
[Unit]
Description=Backup Valheim worlds
[Service]
Type=oneshot
User=steam
Group=steam
ExecStart=/opt/valheim/scripts/backup.sh
EOF
sudo tee /etc/systemd/system/valheim-backup.timer >/dev/null <<'EOF'
[Unit]
Description=Schedule Valheim backups
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now valheim-backup.timer
sudo systemctl list-timers --all | grep valheim-backup || true
7. Mod management with BepInEx (server)
To run mods, install the BepInEx pack for Valheim on the server. Download the package locally, upload the .zip to the VPS and extract it into the server directory. Stop the service before changing mods. After the first start with BepInEx, the plugins folder will be created.
General install steps:
- Upload the BepInEx ZIP to /tmp on the VPS.
- Extract it into the server directory.
- Start the server once to generate BepInEx/ and configs.
- Place mods in BepInEx/plugins. Clients usually need the same mods.
# Supondo o pacote em /tmp/BepInExPack_Valheim_x64.zip
sudo systemctl stop valheim
sudo -u steam unzip -o /tmp/BepInExPack_Valheim_x64.zip -d /opt/valheim
# Inicie uma vez para gerar BepInEx/ e configs
sudo systemctl start valheim
sleep 10
sudo systemctl stop valheim
# Exemplo: instalar um mod (ZIP contendo pastas do BepInEx)
sudo -u steam unzip -o /tmp/AlgumMod.zip -d /opt/valheim
sudo systemctl start valheim
8. Updates, logs and troubleshooting
Keep the server updated via SteamCMD. Check logs with journalctl and BepInEx logs. If something breaks, revert to a recent backup. Game and mod updates should be coordinated to avoid incompatibilities.
Quick diagnostic tips:
- Port not visible: verify UFW, provider rules and that UDP 2456 is listening.
- Crashes: check VPS resources and recent mods.
- Version mismatches: align client, server and mod versions.
- Invalid password: use a strong password without odd characters.
# Atualizar servidor dedicado
sudo -u steam /usr/games/steamcmd +login anonymous \
+force_install_dir /opt/valheim \
+app_update 896660 validate +quit
# Reiniciar e acompanhar logs
sudo systemctl restart valheim
sudo journalctl -u valheim -f
Frequently asked questions
Which ports do I need to open for a Valheim server?
The server uses UDP ports 2456 to 2458 by default. Open these ports in the VPS firewall and, if applicable, in the provider panel. If you change the port in the script, adjust the range accordingly. Use tools like ss or netstat to confirm the port is listening.
Where are the world files and how do I restore a backup?
In this guide, saves are stored in /opt/valheim/data (set by -savedir). To restore, stop the service, extract the backup .tgz into that folder and restart. Regularly test restores in a staging environment to ensure data integrity.
How do I update the server without losing progress?
Stop the server, run SteamCMD to update, then start it again. Always make a backup before updating. If you run mods, check that mod versions are compatible with the game update. If issues occur, restore the latest backup and test mods individually.
Can I use mods? Do players need to install them too?
Yes. Install BepInEx on the server and place mods in BepInEx/plugins. Generally, players need the same mods and matching versions on their clients. Keep a clear list of mods and versions for your group and update them in a coordinated way.
How do I move the server to another VPS?
Copy the installation folder (/opt/valheim) and, importantly, the data directory (-savedir) to the new VPS. Recreate the systemd service, open the required ports and test. If you use versioned backups, migration usually involves restoring a backup and updating DNS as needed.
Need help keeping your server stable?
I can help automate backups, set up monitoring and provide ongoing maintenance for your Valheim server on a VPS.
Discuss automation and maintenanceSee also
- Tutorial: Implement Canary releases with Traefik in Docker Compose using headers and weighted routing for gradual PHP deployments
- Tutorial: Configure HAProxy with Let's Encrypt and health checks to load balance traffic between Docker containers on a VPS (step-by-step)
- Hands‑On Tutorial: Implement mTLS Between Nginx and Microservices with smallstep CA in Docker Compose
- Tutorial: configure cgroup v2 and systemd ResourceControl to limit CPU, memory and I/O for Docker containers on Debian