To avoid potential security risks, it is not recommended to run applications under the root
account.
Creating a Valheim server with Scaleway
- gaming
- Valheim
Valheim Server - Overview
Valheim is a survival and sandbox video game that was released in early access on 2 February 2021 for Windows and Linux on Steam. Within only one month after its release the game sold more than 5 million copies and is one of the most played games on Steam.
Players of the game are Vikings in an afterlife where they have to complete missions like crafting tools, building shelters, and fighting enemies to survive. The game has multiple biomes available, such as meadows, swamps, ashlands, mountains, and oceans. Each of these biomes is unique and comes with its own difficulty level - which means players are confronted with different items and enemies. Players can travel through these biomes by either foot or boat. The game supports multiplayer mode with up to ten concurrent players.
At Scaleway, we offer a large range of Instances that will suit the gaming needs of your Valheim server. In this tutorial, you will learn how to create your own Valheim server with Scaleway Instances.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- An SSH key
Deploying an Instance
- Click Instances in the Compute section of the side menu. The Instances page displays.
- Click Create Instance. The Instance creation page displays.
- Enter the required information for your Instance:
- The Availability Zone is the geographical region in which your Instance will be deployed. In this tutorial, we use
FR-PAR2
, but you can choose the one closest to your location. - The image that runs on your Instance. In this tutorial, we use Ubuntu Focal Fossa (20.04)
- An Instance type. It characterizes the performances of your Instance. In this tutorial, we use a DEV1-L Instance which provides 8 GB RAM. If required you can choose a more powerful Instance for very large multiplayer sessions.
- The Availability Zone is the geographical region in which your Instance will be deployed. In this tutorial, we use
- Click Create Instance to deploy the Instance. You can click on this link to have the Instance creation page prefilled with the required information. If you have the Scaleway CLI installed on your computer, you can also use the following command to deploy the Instance:
scw instance server create type=DEV1-L zone=fr-par-2 image=ubuntu_focal root-volume=l:80G name=valheim-server ip=new
Installing SteamCMD
- Log into your Instance using SSH.
- The Valheim Server requires SteamCMD, a command line client of the Steam client. It requires the
i386
architecture available in theapt
package manager. Add it with the following command:dpkg --add-architecture i386 - Update the
apt
package repositories and upgrade the software already installed on the machine to the latest version available in Ubuntu’s repositoriesapt update && apt upgrade -y - Install
steamcmd
and its prerequisites using theapt
package manager:apt install curl wget file tar bzip2 gzip unzip bsdmainutils python util-linux ca-certificates binutils bc jq tmux netcat lib32gcc1 lib32stdc++6 steamcmd sudo ufw
Installing the Valheim server
-
Create a new
valheim
user account using the following command:adduser valheim -
Add the
valheim
user to the SuDoers file:adduser valheim sudo -
Change into the
valheim
user account:su valheim -
Change into the user’s home directory:
cd ~/ -
Create a new sub-folder in the user’s home directory to store the Valheim server files in:
mkdir valheim-server -
Run the following command to download the Valheim server files into the newly created directory using
steamcmd
:steamcmd +login anonymous +force_install_dir /home/valheim/valheim-server +app_update 896660 validate +exitThe Steam command line tool downloads the latest updates and installs the Valheim server into our directory. This may take some time. Once completed the following message displays:
Success! App '896660' fully installed. -
Change into the
valheim-server
directory and make a copy of thestart_server.sh
script to avoid it being overwritten by an eventual update of Steam:cd valheim-server && cp start_server.sh start_valheim_server.sh -
Open the script in a text editor, for example
nano
:nano start_valheim_server.sh -
Modify the script as follows to download automatically the latest Valheim updates from Steam during the applications’ start. Replace the values
My Server
with the name of your server,Dedicated
with the world you want to use on the server, andsecret_password
with your servers password. Make sure to edit the path of yourvalheim_server
executable to the complete path to the binary file. Once edited, save the file by pressing CTRL+O, then leave nano by pressing CTRL+X.export templdpath=$LD_LIBRARY_PATHexport LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATHexport SteamAppId=892970echo "Downloading application updates."/home/valheim/.steam/steamcmd/steamcmd.sh +login anonymous +force_install_dir /home/valheim/valheim-server/ +app_update $SteamAppID +quitecho "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 & the password can't be in the server name.# NOTE: You need to make sure the ports 2456-2458 are being forwarded to your server through your firewall./home/valheim/valheim-server/valheim_server.x86_64 -name "My server" -port 2456 -world "Dedicated" -password "secret_password"export LD_LIBRARY_PATH=$templdpathecho "Server started." -
Start the Valheim server by running the following command:
./start_valheim_server.sh
Creating a systemd service
Currently, we can launch the Valheim server manually by connecting using SSH. However, after a server reboot, it will not start automatically again. We use systemd to automatically launch the Valheim server application after a reboot of our server.
-
Create a new systemd service file called
valheim.service
and open it innano
or another text editor of your choicesudo touch /etc/systemd/system/valheim.service && sudo nano /etc/systemd/system/valheim.service -
Copy and paste the following content into the service file. It tells SystemD to launch the Valheim server automatically during boot once the network is ready:
[Unit]Description=Valheim Server ServiceWants=network.targetAfter=syslog.target network-online.target[Service]Type=simpleRestart=on-failureRestartSec=10User=valheimWorkingDirectory=/home/valheim/valheim-server/ExecStart=/bin/bash /home/valheim/valheim-server/start_valheim_server.sh[Install]WantedBy=multi-user.targetSave the service file by pressing CTRL+O, then leave
nano
by pressing CTRL+X. -
Reload the systemd daemon to make the new service available on the system:
sudo systemctl daemon-reload -
Enable the new service so that it starts automatically upon the next reboot of the instance:
sudo systemctl enable valheim.service -
Start the Valheim Server service:
sudo systemctl start valheim.service -
Wait a few seconds and run the following command to see if the Valheim server runs:
sudo systemctl status valheim.serviceIf ever you want to stop your Valheim server, run the following command:
sudo systemctl stop valheim.service
Protecting the server
You can configure Uncomplicated Firewall (UFW) to restrict access to our Valheim game server for security reasons. Drop all connections except SSH and the ports of our Valheim server application.
-
Check the status of the firewall. It should be deactivated before we configure it:
sudo ufw status -
Add the following rules to the configuration:
sudo ufw deny anysudo ufw allow sshsudo ufw allow 2456:2458/udpThe rules above drop all incoming connections by default, but allow SSH connections and connections to the ports
2456
-2458
, which are used by the Valheim server. -
Enable the firewall by running the following command:
sudo ufw enable
Conclusion
You have now configured your own Valheim server on a Scaleway Instance, installed basic protection through UFW, and are ready to invite your friends to explore the different worlds of Valheim. For more information about the game, refer to the official Valheim website.