Valheim Dedicated Server on Linux
Valheim is a popular Viking-themed survival game that supports dedicated server hosting on Linux. Running your own dedicated server gives you complete control over game settings, world configuration, and administrative features. This guide covers the complete process of setting up a production-ready Valheim dedicated server on Linux with proper systemd management, automated backups, and optimization techniques.
Table of Contents
- System Requirements
- Installing SteamCMD
- Installing Valheim Server
- Server Configuration
- Port Configuration and Firewall
- Running with Systemd
- World Management
- Mod Installation with BepInEx
- Backup and Recovery
- Performance Optimization
- Monitoring and Maintenance
- Conclusion
System Requirements
Before installing Valheim server, ensure your system meets these requirements:
- Ubuntu 20.04 LTS or CentOS 7+ (or compatible Linux distribution)
- 4GB RAM minimum (8GB recommended)
- 20GB free disk space
- Stable internet connection
- Root or sudo access
Valheim server requires 64-bit Linux. The server is headless, meaning it doesn't require X11 or a graphical display.
Installing SteamCMD
SteamCMD is Valve's command-line Steam client used to download and manage game servers.
sudo apt-get update
sudo apt-get install -y curl wget file bzip2 gzip unzip python3 util-linux ca-certificates binutils bc jq tmux netcat
Create a dedicated Steam user for security:
sudo useradd -m -s /bin/bash steam
sudo -u steam mkdir -p /home/steam/steamcmd
Download and extract SteamCMD:
cd /home/steam/steamcmd
sudo -u steam curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | sudo -u steam tar zxvf -
Verify installation by running SteamCMD:
sudo -u steam /home/steam/steamcmd/steamcmd.sh +quit
Installing Valheim Server
Install the Valheim server using SteamCMD. The app ID for Valheim dedicated server is 896660.
sudo -u steam /home/steam/steamcmd/steamcmd.sh +force_install_dir /home/steam/valheim +login anonymous +app_update 896660 validate +quit
Verify the installation by checking for key executable files:
ls -la /home/steam/valheim/
file /home/steam/valheim/valheim_server.x86_64
Create necessary directories for server data:
sudo -u steam mkdir -p /home/steam/valheim-data/worlds
sudo -u steam mkdir -p /home/steam/valheim-data/logs
sudo -u steam chmod 755 /home/steam/valheim-data
Server Configuration
Create the main server startup script. This script will handle server arguments and logging:
sudo tee /home/steam/valheim/start_server.sh > /dev/null <<'EOF'
#!/bin/bash
VALHEIM_DIR="/home/steam/valheim"
DATA_DIR="/home/steam/valheim-data"
SERVER_NAME="${SERVER_NAME:-ValheimServer}"
SERVER_PORT="${SERVER_PORT:-2456}"
SERVER_PASSWORD="${SERVER_PASSWORD:-changeme}"
WORLD_NAME="${WORLD_NAME:-Dedicated}"
BACKUP_DIR="${BACKUP_DIR:-$DATA_DIR/backups}"
cd "$VALHEIM_DIR"
mkdir -p "$DATA_DIR/worlds"
mkdir -p "$BACKUP_DIR"
exec "$VALHEIM_DIR/valheim_server.x86_64" \
-nographics \
-batchmode \
-server \
-serverport "$SERVER_PORT" \
-name "$SERVER_NAME" \
-world "$WORLD_NAME" \
-password "$SERVER_PASSWORD" \
-savedir "$DATA_DIR/worlds" \
-logFile "$DATA_DIR/logs/valheim.log" \
2>&1
EOF
Make the script executable:
sudo chmod +x /home/steam/valheim/start_server.sh
sudo chown steam:steam /home/steam/valheim/start_server.sh
Test the server startup:
sudo -u steam bash -c 'SERVER_NAME="TestServer" SERVER_PORT=2456 SERVER_PASSWORD="test123" WORLD_NAME="TestWorld" timeout 10 /home/steam/valheim/start_server.sh || true'
tail -f /home/steam/valheim-data/logs/valheim.log
Port Configuration and Firewall
Valheim uses UDP ports for server communication. The default configuration uses three consecutive ports:
- Primary port (default 2456): Game server UDP
- Secondary port (+1): Server discovery/sync UDP
- Tertiary port (+2): Server query UDP
Configure UFW firewall:
sudo ufw allow 2456:2458/udp
sudo ufw allow 2456:2458/tcp
sudo ufw status numbered
For iptables-based systems:
sudo iptables -A INPUT -p udp --dport 2456:2458 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 2456:2458 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4
Verify port listening:
sudo netstat -ulnp | grep valheim_server
ss -ulnp | grep 2456
Running with Systemd
Create a systemd service file for automatic startup and management:
sudo tee /etc/systemd/system/valheim.service > /dev/null <<'EOF'
[Unit]
Description=Valheim Dedicated Server
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=steam
Group=steam
WorkingDirectory=/home/steam/valheim
EnvironmentFile=/home/steam/valheim/server.env
ExecStart=/home/steam/valheim/start_server.sh
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
# Resource limits
LimitNOFILE=65536
LimitNPROC=32768
# Security
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=yes
ReadWritePaths=/home/steam/valheim-data
[Install]
WantedBy=multi-user.target
EOF
Create environment configuration file:
sudo tee /home/steam/valheim/server.env > /dev/null <<'EOF'
SERVER_NAME=ValheimServer
SERVER_PORT=2456
SERVER_PASSWORD=ChangeMeToSecurePassword
WORLD_NAME=Dedicated
EOF
Fix permissions:
sudo chown steam:steam /home/steam/valheim/server.env
sudo chmod 600 /home/steam/valheim/server.env
sudo chown steam:steam /home/steam/valheim-data
sudo chmod 755 /home/steam/valheim-data
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable valheim.service
sudo systemctl start valheim.service
sudo systemctl status valheim.service
Monitor service logs in real-time:
sudo journalctl -u valheim.service -f
sudo journalctl -u valheim.service -n 100
World Management
Valheim stores world data in the save directory. Each world consists of multiple files containing terrain, structure, and player data.
List available worlds:
ls -lah /home/steam/valheim-data/worlds/
file /home/steam/valheim-data/worlds/*
World files include:
.fwl: World metadata.db: Player and structure database.fwl.meta: Additional metadata
Create a backup of a specific world:
WORLD_NAME="Dedicated"
BACKUP_DIR="/home/steam/valheim-data/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
sudo -u steam bash -c "cp -r /home/steam/valheim-data/worlds/$WORLD_NAME.* $BACKUP_DIR/world_${WORLD_NAME}_${TIMESTAMP}/"
Reset or delete a world:
sudo systemctl stop valheim.service
sudo -u steam rm -f /home/steam/valheim-data/worlds/Dedicated.*
sudo systemctl start valheim.service
Generate a new world with custom seed:
# Set WORLD_NAME and restart service
sudo systemctl stop valheim.service
sudo -u steam /home/steam/valheim/start_server.sh 2>&1 | head -20
sleep 5
sudo systemctl kill valheim.service
sudo systemctl start valheim.service
Mod Installation with BepInEx
BepInEx is a mod loader for Valheim that enables plugin functionality. This is optional but recommended for enhanced server management.
Download BepInEx:
cd /home/steam/valheim
BEPINEX_VERSION="5.4.21"
sudo -u steam wget https://github.com/BepInEx/BepInEx/releases/download/v${BEPINEX_VERSION}/BepInEx_x64_${BEPINEX_VERSION}.zip
Extract BepInEx:
sudo -u steam unzip -o BepInEx_x64_${BEPINEX_VERSION}.zip
sudo -u steam chmod +x valheim_server.x86_64
Install mod dependencies (optional but recommended):
# Example: Install useful server management plugins
cd /home/steam/valheim/BepInEx/plugins
sudo -u steam wget https://github.com/nxPublic/BepInEx-Tools/releases/download/BepInEx-Tools_v2.2/BepInEx-Tools_v2.2.zip
sudo -u steam unzip -o BepInEx-Tools_v2.2.zip
Verify BepInEx initialization by checking logs:
tail -50 /home/steam/valheim-data/logs/valheim.log | grep -i bepinex
Backup and Recovery
Implement automated daily backups with retention policy:
sudo tee /home/steam/backup_valheim.sh > /dev/null <<'EOF'
#!/bin/bash
DATA_DIR="/home/steam/valheim-data"
BACKUP_DIR="$DATA_DIR/backups"
RETENTION_DAYS=30
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
# Create backup
mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_DIR/valheim_backup_${TIMESTAMP}.tar.gz" \
-C "$DATA_DIR" worlds/ \
2>/dev/null
if [ $? -eq 0 ]; then
echo "[$(date)] Backup created: valheim_backup_${TIMESTAMP}.tar.gz"
else
echo "[$(date)] Backup failed!" >&2
exit 1
fi
# Remove old backups
find "$BACKUP_DIR" -name "valheim_backup_*.tar.gz" -mtime +${RETENTION_DAYS} -delete
echo "[$(date)] Old backups cleaned (retention: ${RETENTION_DAYS} days)"
EOF
sudo chmod +x /home/steam/backup_valheim.sh
sudo chown steam:steam /home/steam/backup_valheim.sh
Add daily backup to crontab:
sudo tee -a /var/spool/cron/crontabs/steam > /dev/null <<'EOF'
0 3 * * * /home/steam/backup_valheim.sh >> /home/steam/valheim-data/logs/backup.log 2>&1
EOF
sudo systemctl restart cron
Restore from backup:
# List available backups
ls -lh /home/steam/valheim-data/backups/
# Restore specific backup
sudo systemctl stop valheim.service
BACKUP_FILE="/home/steam/valheim-data/backups/valheim_backup_20240101_030000.tar.gz"
sudo -u steam tar -xzf "$BACKUP_FILE" -C /home/steam/valheim-data/
sudo systemctl start valheim.service
Performance Optimization
Optimize system settings for game server performance:
# Increase file descriptors
sudo sysctl -w fs.file-max=2097152
echo "fs.file-max=2097152" | sudo tee -a /etc/sysctl.conf
# Network optimizations
sudo sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sudo sysctl -w net.ipv4.tcp_fin_timeout=30
sudo sysctl -w net.core.somaxconn=1024
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=2048
Monitor resource usage:
# Real-time monitoring
watch -n 1 'ps aux | grep valheim_server'
htop -p $(pgrep -f valheim_server)
# Memory usage
ps -o pid,vsz,rss,comm $(pgrep -f valheim_server)
# Network statistics
netstat -s | grep -i "udp"
ss -s
Set CPU affinity for better performance (optional):
# Get PID
PID=$(pgrep -f valheim_server)
# Set to use cores 0-3 (adjust based on your server)
taskset -p -c 0-3 $PID
# Verify
taskset -p $PID
Monitoring and Maintenance
Create a monitoring script to check server health:
sudo tee /home/steam/check_valheim.sh > /dev/null <<'EOF'
#!/bin/bash
PROCESS_NAME="valheim_server"
LOG_FILE="/home/steam/valheim-data/logs/valheim.log"
PORT=2456
# Check if process is running
if pgrep -f "$PROCESS_NAME" > /dev/null; then
echo "✓ Server process is running"
else
echo "✗ Server process is NOT running"
exit 1
fi
# Check port
if netstat -ulnp 2>/dev/null | grep -q $PORT; then
echo "✓ Server listening on port $PORT"
else
echo "✗ Server NOT listening on port $PORT"
fi
# Check log for errors
RECENT_ERRORS=$(tail -50 "$LOG_FILE" | grep -i "error\|exception\|fatal" | wc -l)
echo "Recent errors in log: $RECENT_ERRORS"
# Check disk space
DISK_USAGE=$(df -h /home/steam/valheim-data | awk 'NR==2 {print $5}')
echo "Disk usage: $DISK_USAGE"
# Memory usage
MEM_USAGE=$(ps aux | grep $PROCESS_NAME | grep -v grep | awk '{print $6}')
echo "Memory usage: ${MEM_USAGE}KB"
EOF
sudo chmod +x /home/steam/check_valheim.sh
Update server to latest version:
sudo systemctl stop valheim.service
sudo -u steam /home/steam/steamcmd/steamcmd.sh \
+force_install_dir /home/steam/valheim \
+login anonymous \
+app_update 896660 validate \
+quit
sudo systemctl start valheim.service
Conclusion
You now have a fully functional Valheim dedicated server running on Linux with systemd management, automated backups, and proper networking configuration. This setup provides a reliable foundation for running a multiplayer Valheim server with complete administrative control.
Key points to remember:
- Change the server password to a secure value immediately
- Implement regular backups using the provided scripts
- Monitor logs regularly for issues
- Keep the server updated with the latest SteamCMD updates
- Use BepInEx mods carefully to maintain server stability
- Plan for scaling if player count increases
Regular maintenance, monitoring, and backups are essential for long-term server stability and data protection.


