Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active May 21, 2024 16:22
Show Gist options
  • Save mattiasghodsian/c988e8c8954be46f35c33311f26f0c50 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/c988e8c8954be46f35c33311f26f0c50 to your computer and use it in GitHub Desktop.
Valheim Dedicated Server Setup on Ubuntu 20.04.1 LTS

Port forwarding

Open ports (udp)

2456 2457 2458 27060

Uncomplicated Firewall

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

Setup SteamCMD

Add multiverse repo

sudo add-apt-repository multiverse

Add i386 architecture

sudo dpkg --add-architecture i386

Update and install SteamCMD

sudo apt update && sudo apt install lib32gcc1 steamcmd 

Install server files

Make a new folder in your home directory example /home/tattoine/valheim

mkdir valheim && cd valheim

Install Valheim server files (change directory/username)

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

Create your own start script (use your preferred editor)

nano start_valheim.sh

Paste below to start_valheim.sh (change directory/username)

#!/bin/bash

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

# Tip: Make a local copy of this script to avoid it being overwritten by steam.
# NOTE: Minimum password length is 5 characters & Password cant be in the server name.
# NOTE: You need to make sure the ports 2456-2458 is being forwarded to your server through your local router & firewall.
/home/tattoine/.steam/steamcmd/steamcmd.sh +login anonymous +force_install_dir /home/tattoine/valheim +app_update 896660 +quit

./valheim_server.x86_64 -name "Banana Fury" -port 2456 -nographics -batchmode -world "Dedicated" -password "hello123" -public 1 > /dev/null &
export LD_LIBRARY_PATH=$templdpath

echo "Server started"

Setting execute permissions

chmod +x start_valheim.sh

Create a service script (use your preferred editor)

nano valheim.service

Paste below to start_valheim.sh (change directory/username)

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

[Service]
Type=simple
Restart=on-failure
RestartSec=10
StartLimitInterval=60s
StartLimitBurst=3
User=steam
Group=steam
ExecStartPre=/home/tattoine/.steam/steamcmd/steamcmd.sh +login anonymous +force_install_dir /home/tattoine/valheim +app_update 896660 validate +exit
ExecStart=/home/tattoine/valheim/start_valheim.sh
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGINT
WorkingDirectory=/home/tattoine/valheim
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target

Copy the service script to systemd and reload the deamon

sudo cp valheim.service /etc/systemd/system && sudo systemctl daemon-reload

Service Start/Stop/Status

sudo systemctl start valheim

Extras

Add service on system boot

sudo systemctl enable valheim.service

Get Steam64ID (one user per row)

nano ~/.config/unity3d/IronGate/Valheim/adminlist.txt

Server Commands

Only whitelisted admins can use commands, Open console with F5

Command Args Description
help Lists all the commands you can use
kick name/ip/userID Kick the user
ban name/ip/userID Ban the user
unban /ip/userID Unban the user
banned List banned users
ping Send a ping to the server to get your latency
lodbias 1 Set distance lod bias. If empty shows actual lodbias. By default 1.5
info System info
@kylebruder
Copy link

This is legit! I got it up and running in less than 20 minutes. Couldn't find the mutliversea repo. Also the steamcmd command executable was installed to '/usr/games/steamcmd' on Ubuntu 20.04.2 LTS. Last thing, I didn't have a 'steam' user so i just used my regular user and group and it works great. Thanks!

@Geordinateur
Copy link

Hello, thanks very much, but my systemd reload every time, do you know why?

@mattiasghodsian
Copy link
Author

@Geordinateur Need more information to be able to help

@Geordinateur
Copy link

if i launch server with script start_valheim.sh it's ok, but if i launch with systemd, the server is restart every 5 min.
I removed "&" in start_valheim.sh now its worked very well

@Choomyo
Copy link

Choomyo commented May 24, 2022

my Valheim server is working but not through systemd.

Im very new to Ubuntu so go easy please.

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

[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=adam
WorkingDirectory= /home/adam/Valheim
ExecStart= /home/adam/valheim/start_valheim.sh
LimitNOFILE-100000

[Install]
WantedBy=multi-user.target

This is what i have in my valheim.service file.

May 21 17:12:51 homeserver systemd[1]: Started Valheim service.
May 21 17:12:51 homeserver systemd[49211]: valheim.service: Failed to locate executable /home/adam/Valheim/start_valheim.sh: No such file or directory
May 21 17:12:51 homeserver systemd[49211]: valheim.service: Failed at step EXEC spawning /home/adam/Valheim/start_valheim.sh: No such file or directory
May 21 17:12:51 homeserver systemd[1]: valheim.service: Main process exited, code=exited, status=203/EXEC
May 21 17:12:51 homeserver systemd[1]: valheim.service: Failed with result 'exit-code'.
May 21 17:13:02 homeserver systemd[1]: valheim.service: Scheduled restart job, restart counter is at 6.
May 21 17:13:02 homeserver systemd[1]: Stopped Valheim service.
May 21 17:13:02 homeserver systemd[1]: Started Valheim service.
May 21 17:13:02 homeserver systemd[49406]: valheim.service: Failed to locate executable /home/adam/Valheim/start_valheim.sh: No such file or directory
May 21 17:13:02 homeserver systemd[49406]: valheim.service: Failed at step EXEC spawning /home/adam/Valheim/start_valheim.sh: No such file or directory
May 21 17:13:02 homeserver systemd[1]: valheim.service: Main process exited, code=exited, status=203/EXEC
May 21 17:13:02 homeserver systemd[1]: valheim.service: Failed with result 'exit-code'.
May 21 17:13:12 homeserver systemd[1]: valheim.service: Scheduled restart job, restart counter is at 7.
May 21 17:13:12 homeserver systemd[1]: Stopped Valheim service.
this is what journal logs are showing

@mattiasghodsian
Copy link
Author

@Choomyo This file is missing /home/adam/Valheim/start_valheim.sh or in the wrong path

@D1srupt3d
Copy link

D1srupt3d commented Jan 15, 2023

sudo add-apt-repository multiverse for anyone having issues with adding the repo. He added and "a" at the end by accident.

Also you are missing 'sudo apt install software-properties-common' which is needed to get lib32gcc-s1 since it is not longer in available with just multiverse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment