Skip to content

Instantly share code, notes, and snippets.

@mmercedes
Last active April 16, 2024 07:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mmercedes/64428eac49d970d6bcac99718a0066a3 to your computer and use it in GitHub Desktop.
Save mmercedes/64428eac49d970d6bcac99718a0066a3 to your computer and use it in GitHub Desktop.
Guide for creating a dedicated valheim server on debian

recommened you do this from within tmux since the steamcmd utility creates its own repl

Install SteamCMD

taken from here

$ sudo useradd -m steam
$ sudo apt update && sudo apt-get install lib32gcc1 -y
$ sudo su - steam
$ mkdir ~/Steam && cd ~/Steam
$ curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -
$ ./steamcmd.sh

The last command should bring you into a steam client repl. From here you can login with your steam account (only required once) so Valheim can downloaded.

Steam> login <steam_username>
# this will prompt for password and two-factor auth
Steam> exit

Install Valheim server

Download Valheim from steam into steam user's homedir

$ mkdir ~/Valheim
$ ./steamcmd.sh +login <steam_username> +force_install_dir /home/steam/Valheim +app_update 896660 validate +exit

Now to make a copy of the server start script and create a systemctl service for it so can be auto ran on boot

cp ~/Valheim/start_server.sh ~/Valheim/start_server_local_copy.sh
nano ~/Valheim/start_server_local_copy.sh

Add this line to the local copy of the server start script so that it authenticates via your steam account prior to launching. Should go right after the echo "Starting server... line and fill in the value for your steam username

/home/steam/Steam/steamcmd.sh +login <steam_username> +force_install_dir /home/steam/Valheim +app_update 896660 +quit

Next edit the values for -name -world and -password in the line that looks like this:

./valheim_server.x86_64 -name "My server" -port 2456 -world "Dedicated" -password "secret"

Save the file and exit nano

Create and start systemd service

touch ~/valheim.service
nano ~/valheim.service

In Nano, paste and save the following

[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/start_server_local_copy.sh

[Install]
WantedBy=multi-user.target

Now to actually create/start the systemd service, switch back to a user with root access as the steam user will not

sudo cp /home/steam/valheim.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl start valheim

after a few seconds, you can check the status of the server process with

sudo systemctl status valheim

once its looks good, enable the service to run automatically at boot

sudo systemctl enable valheim

Enable port forwarding

Out of the scope of this as its highly dependent on your setup, but you will need to open port 2456 for public traffic before users will be able to connect to your server remotely

Copying worlds

you can simply copy/replace the entire worlds folder if you want to transfer your current world to the new server

Windows location:

C:\Users\snipe\AppData\LocalLow\IronGate\Valheim\worlds

Linux location:

~/.config/unity3d/IronGate/Valheim/worlds
@dweremeichik
Copy link

lib32gcc1 has been renamed to lib32gcc-s1 in Debian 11 (Bullseye)

Copy link

ghost commented Feb 1, 2022

Valheim Dedicated Server now requires to be connected anonymously into SteamCMD instead of being connected through your own steam account

Thanks for the tutorial !

@corincorvus
Copy link

curl is not installed on debian.
Pls add curl in the installpart :)

@CyberXnerd
Copy link

Hi
So i tried a lot but i can't get it to work.
Or at least when i check the status it says aktive but i can't connect to the server.
Ports are forwarded, i can ping the machine and in game the name of the server is recognized when i enter the IP. But i can't get a connection.
On a win 10 machine i got it up and Ranking in a few minutes but on debian 10 i don't get it to work. Already wrote on a debian cummunity and got roasted because it seems i am stupid cause i can't get it running but no one can tell me the somution as well. So can somone here help me please?

@pugainhd
Copy link

pugainhd commented Apr 4, 2023

For anyone trying this, make sure the start_server_local_copy.sh does not have "-crossplay" for some reason it stops any traffic from entering the correct port.

@pugainhd
Copy link

CMD installation out of date. After reupdating, can update the server with steamcmd +login anonymous +force_install_dir /home/steam/Valheim +app_update 896660 validate +exit

@professorcheechi
Copy link

For anyone trying this, make sure the start_server_local_copy.sh does not have "-crossplay" for some reason it stops any traffic from entering the correct port.

thank you for this.

@benjaminb24
Copy link

In the local server script, these were the lines I had to customize to get this to work on Debian 12

/home/steam/Steam/steamcmd.sh +force_install_dir /home/steam/Valheim +login anonymous +app_update 896660 validate +quit
./valheim_server.x86_64 -name "BsWorld" -port 2456 -nographics -batchmode -world "BsDedicatedWorld" -password "12045" -public 1

As well as the download "curl" portion and lib32gcc1 has been renamed to lib32gcc-s1

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