This guide walks through setting up a dedicated Valheim server on Ubuntu using SteamCMD, UFW firewall rules, a custom startup script, and a systemd service so the server can automatically start on boot.

The example below installs the Valheim dedicated server into /home/steam/valheim and runs the service as the steam user.

Overview

  • Game: Valheim Dedicated Server
  • Install Path: /home/steam/valheim
  • Service Name: valheim.service
  • Server User: steam
  • Primary Game Ports: UDP 2456, 2457, and 2458
  • Additional UDP Port: 27060
Important: Make sure UDP ports 2456 through 2458 are allowed through the local firewall and forwarded from your router or external firewall to the Valheim server. If these ports are not open, players may not be able to connect.

Step 1: Allow Valheim Ports Through UFW

If UFW is enabled on the server, allow the required UDP ports:

sudo ufw allow 2456/udp
sudo ufw allow 2457/udp
sudo ufw allow 2458/udp
sudo ufw allow 27060/udp

Step 2: Create the Valheim Server Directory

Create the Valheim server directory:

mkdir valheim

If you are already working from the /home/steam directory, this will create:

/home/steam/valheim
Note: This guide assumes you are using a Linux user named steam. If your server uses a different user, adjust the paths and systemd service accordingly.

Step 3: Install the Valheim Dedicated Server with SteamCMD

Use SteamCMD to download and validate the Valheim dedicated server files:

steamcmd +force_install_dir /home/steam/valheim +login anonymous +app_update 896660 validate +exit

This installs the Valheim dedicated server files into:

/home/steam/valheim

Step 4: Create the Valheim Startup Script

Create a custom startup script for the Valheim server:

nano /home/steam/valheim/valheim_service_start_server.sh

Paste the following into the file:

#!/bin/bash

export templdpath=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH
export SteamAppId=892970

echo "Starting server PRESS CTRL-C to exit"

# Tip: Make a local copy of this script to avoid it being overwritten by steam.
# NOTE: Minimum password length is 5 characters and the password cannot be in the server name.
# NOTE: Make sure ports 2456-2458 are forwarded to your server through your local router and firewall.

./valheim_server.x86_64 -name "yourservername" -port 2456 -nographics -world "yourworldfilename" -password "yourpassword" -crossplay

export LD_LIBRARY_PATH=$templdpath
Important: Replace yourservername, yourworldfilename, and yourpassword with your actual server name, world name, and password.

Step 5: Make the Startup Script Executable

Change into the Valheim directory:

cd valheim

Make the startup script executable:

sudo chmod +x valheim_service_start_server.sh

Step 6: Create the systemd Service

Create a new systemd service file:

sudo nano /etc/systemd/system/valheim.service

Paste the following into the file:

[Unit]
Description=Valheim service
Wants=network.target
After=syslog.target network-online.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=steam
WorkingDirectory=/home/steam/valheim
ExecStart=/bin/bash /home/steam/valheim/valheim_service_start_server.sh
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target
Note: The service file points to /home/steam/valheim/valheim_service_start_server.sh. Make sure the startup script name matches exactly.

Step 7: Reload systemd

Reload systemd so it detects the new Valheim service:

sudo systemctl daemon-reload

Step 8: Start the Valheim Server

Start the Valheim service:

sudo systemctl start valheim

Step 9: Check the Valheim Service Status

Check whether the service started successfully:

sudo systemctl status valheim

If the server is running correctly, the service should show as active.

Step 10: Enable the Server on Boot

Enable the Valheim service so it starts automatically when the server boots:

sudo systemctl enable valheim.service

World Save Location

Valheim world files are stored in the following location for the steam user:

/home/steam/.config/unity3d/IronGate/Valheim/worlds_local
Backup Tip: Before updating or making major server changes, back up the worlds_local folder.

Useful Management Commands

Restart the Valheim server:

sudo systemctl restart valheim

Stop the Valheim server:

sudo systemctl stop valheim

View live Valheim service logs:

sudo journalctl -u valheim -f

Updating the Valheim Server

To update the Valheim dedicated server, stop the service, run SteamCMD again, then start the service:

sudo systemctl stop valheim

steamcmd +force_install_dir /home/steam/valheim +login anonymous +app_update 896660 validate +exit

sudo systemctl start valheim

Troubleshooting

  • If the server does not show online, confirm UDP ports 2456, 2457, and 2458 are forwarded through your router or external firewall.
  • If the service fails to start, check the service logs with sudo journalctl -u valheim -f.
  • If the startup script fails, confirm the script is executable.
  • If players cannot connect, confirm the server password is at least 5 characters and is not part of the server name.
  • If the world does not load correctly, confirm the world name matches the world file name in the Valheim worlds folder.

Summary

After completing these steps, the Valheim dedicated server should be installed under /home/steam/valheim, controlled by a systemd service, and configured to automatically start on boot. The server can be managed with normal systemctl commands.