How to Install a TF2 Server on a VPS
Written by Aaron "Aar" Pearson
Last updated October 6, 2024
Initialization
- Log in to your Hetzner account or sign up with my referral link. (This guide previously used DigitalOcean)
- Click Continue and then click Sign Up on the next page
- Log in with your account or create a new one. If this is a new account, you may have to deposit €20 to verify it before it is usable. This will stack on top of your free referral credits.
- Navigate to https://console.hetzner.cloud/projects and create a new project
- Navigate into your project, select Servers, then click Add Server
- Select the server region closest to you/your players
- Select Ubuntu 24.04 LTS (or whichever LTS release is the latest). This must SPECIFICALLY be an LTS release.
- Select your desired CPU type. A Dedicated x86 Server with 2 vCPUs is my recommendation for a 16+ player TF2 server. (Shared x86 vCPUs will get less resources and are "shared" with other Hetzner users, hence the name. They are typically not recommended for high-usage applications like this, but could be fine for low-player trade servers etc.)
- Select "Public IPv4" and "Public IPv6" networking options
- Enter a hostname for your VDS
- Create the VDS
- Wait for the VDS to initialize, and copy its IP Address once it finishes
- Install PuTTY on your computer
- Paste the IP Address into PuTTY
- Enter "root" as the username, press enter
- Enter the root password that was sent to you via email by Hetzner
- After logging in, enter the root password again
- Set up a new password and enter it again when prompted
- Run useradd tfds (replace tfds with your desired user name every time tfds is mentioned)
- Run passwd tfds to set a password (ideally different from the root password set earlier)
- Run usermod -aG sudo tfds
- Run sudo usermod --shell /bin/bash tfds
- Run sudo mkdir /home/tfds
- Run sudo chown tfds /home/tfds
- Close PuTTY and reopen it. Re-enter your VDS's IP
- Enter the username you specified
- Enter your password
- Run sudo nano /etc/ssh/sshd_config
- Press the down arrow key until you find the text PermitRootLogin yes
- Change PermitRootLogin yes to PermitRootLogin no using your keyboard
- Press Ctrl + X, then Y, then Enter
- Run sudo service sshd restart
- Run sudo apt update and then run sudo apt upgrade -y
- Close PuTTY and reopen it and sign in as the tfds user
Install SteamCMD and TF2 Dedicated Server
- Run sudo mkdir /hlserver
- Run sudo chmod 775 /hlserver
- Run sudo chown tfds /hlserver to get permissions
- Run cd /hlserver
- Run sudo dpkg --add-architecture i386
- Run sudo apt update
- Run sudo apt install lib32z1 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 -y
- Run wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
- Run tar zxf steamcmd_linux.tar.gz
- Run nano tf2_ds.txt
- Enter force_install_dir /hlserver/tf2 and press the Enter key
- Enter login anonymous and press the Enter key
- Enter app_update 232250 and press the Enter key
- Enter quit
- Press Ctrl + X, then Y, then Enter
- Run nano update.sh
- Enter ./steamcmd.sh +runscript tf2_ds.txt
- Press Ctrl + X, then Y, then Enter
- Run sudo chmod +x steamcmd.sh update.sh
- Run ./update.sh and wait for the installation to finish (If the download errors out, simply run ./update.sh again to resume from where it left off).
Testing TF2 Dedicated Server
- Run mkdir /home/tfds/.steam
- Run ln -s /hlserver/linux64 /home/tfds/.steam/sdk64
- Run ln -s /hlserver/linux32 /home/tfds/.steam/sdk32
- Run nano tf.sh
- Enter #!/bin/sh and press the Enter key
- Enter tf2/srcds_run -console -game tf -timeout 0 -autoupdate -steam_dir /hlserver -steamcmd_script /hlserver/tf2_ds.txt followed by additional parameters of your choosing
- Visit this wiki entry to see additional parameters and use +maxplayers 24 +map ctf_2fort +sv_pure 0 as a base
- (Use srcds_run_64 in place of srcds_run to use a 64-bit server executable. This will likely break SourceMod plugin compatibility.)
- Press Ctrl + X, then Y, then Enter
- Run sudo chmod +x tf.sh
- Run ./tf.sh to start the game server and wait for files to verify and for the map to start
- Open Team Fortress 2 on your client computer and enter the console command connect x (replace x with VDS's IP)
- Verify that you successfully loaded into the map you specified in tf.sh
- Press Ctrl + C in PuTTY to terminate the game server session
Additional Setup and Customization
- Run sudo ufw allow 22
- Run sudo ufw allow 80
- Run sudo ufw allow 27015
- Run sudo ufw enable
- Install FileZilla on your computer (watch out for sponsored offers in the default installer)
- Connect to your VDS by entering its IP, your username and password, followed by port 22 for sFTP
- Enter the hlserver, tf2, and tf folders
- Enter the cfg folder
- Visit avi12's TF2 server cfg generator website on your client computer
- Enter the settings you would like to use for your game server
- When prompted for sv_maxrate, enter 0
- When prompted for net_chan_limit_msec, enter 128. Increase this number to 192 or decrease it to 0 (to disable the feature) if players are frequently kicked with "processing time exceeded."
- When prompted for sv_downloadurl, enter http://x/fastdl/tf/ (replace x with your VDS's IP)
- Download your server.cfg file
- Drag and drop the server.cfg file into FileZilla as shown in my video
- Right-click on server.cfg from your VDS in FileZilla and click View/Edit
- OPTIONAL: Make a new line at the bottom of the file and enter sm_cvar nb_update_frequency 0.03. This will make NPCs (NextBots) smoother for players with low interpolation, but will cause increased CPU usage (and Monoculus will fire much faster).
- OPTIONAL: Make another new line and enter sm_cvar tf_halloween_gift_lifetime 0 to prevent Ghost Gargoyles from spawning.
- When prompted to re-upload the file with your changes, select Yes
- Right-click your VDS's window in FileZilla and click Create empty file
- Name this file mapcycle.txt
- View/Edit mapcycle.txt with a list of map filenames you intend to run on the server, one per line (ex. "cp_gravelpit_snowy")
- Save your changes and re-upload the file when prompted
- Right-click your VDS's window in FileZilla and click Create empty file
- Name this file motd.txt
- View/Edit motd.txt to show a message (or URL) to users when they connect to your server
- Save your changes and re-upload the file when prompted
Installing SourceMod
- Select the .. folder in FileZilla to go up one directory and return to /hlserver/tf2/tf
- Navigate to the Metamod:Source website and download the latest stable Linux build
- Extract the downloaded file with a program of your choice (I recommend 7-Zip)
- Drag and drop the addons folder to your VDS's window in FileZilla and wait for the copy to finish
- Navigate to the SourceMod website and download the latest stable/dev Linux build (some plugins require dev builds)
- Extract the downloaded file with a program of your choice (I recommend 7-Zip)
- Drag and drop the addons and cfg folders to your VDS's window in FileZilla and wait for the copy to finish
- Navigate to the addons folder, the sourcemod folder, and the configs folder
- Right-click on admins_simple.ini and click View/Edit
- Visit steamid.io and copy your steamID
- Paste your steamID on the last line of admins_simple.ini, surrounded by quotes, and press the Tab key
- Enter "99:z" to give yourself full root access
- Save the file and re-upload when prompted by FileZilla
Keeping the Server Running
- Re-open PuTTY
- Run screen -S tf2 to create a new session for TF2 that persists
- Run cd /hlserver
- Run ./tf.sh
- Press Ctrl + A and then the D key to disconnect from the screen session
- Run screen -r to reconnect to the session, and remember this information for later
- You will need to repeat this set of steps after every server reboot
Testing the TF2 Server Again
- Open Team Fortress 2 on your local computer
- Run the command connect x (replacing x with your VDS's IP)
- Run the command sm in the console and check for errors
- Use sm_rcon to run commands on the server's command line
Hosting Workshop Maps
- Enter the command changelevel workshop/xxxxxx in your server's command line (replace xxxxxx with the ID of the Workshop map)
- You can also use this syntax in mapcycle.txt
Setting up Locally-Hosted Maps
- Run sudo apt-get install apache2
- Run sudo systemctl restart apache2
- Run sudo chmod 775 -R /var/www/html/
- Run sudo chgrp -R tfds /var/www/html/
- Open a connection to your VDS in FileZilla
- Navigate to the var, www, and html folders
- Create a new folder titled fastdl and enter it
- Create a new folder titled tf and enter it
- Create a new folder titled maps and enter it
- Place bz2-compressed versions of maps you would like to host in this folder
- Place bsp maps you would like to host in /hlserver/tf2/tf/download/maps (you will need to create the "maps" folder)
Recommended Plugins and Tools
- Steph's AntiCheat - automatically detects and bans many known cheats; a must-have
- Updater - updates any applicable installed SourceMod plugins automatically
- TF2 Comp Fixes - includes a bunch of neat quality-of-life fixes and optional enhancements, including disabling souls
- GroundFix - fixes stopping dead in your tracks when hitting a slope (not needed if you use TF2 Comp Fixes)
- NativeVotes Updated - enables players to vote for another map from the mapcycle near the end of the current match (requires disabling/deleting the "nextmap" plugin)
- Fix ConTracker Animation Exploit - disables the buggy contracker animation
- Basic Votekick Immunity - restricts admins from being votekicked by regular players or idle timers
- WaitingDoors - opens spawn doors during the "waiting for players" phase
- Automatic Steam Update - restarts the server automatically after an update releases; needs SteamWorks and update check)
- Unused Voicelines - plays announcer voice lines from casual mode; up to personal preference.
- rafradek's srcds optimizer - dramatically reduces the CPU usage of the server; 3 packages available depending on your needs ("optimize-only" default). Based on sigsegv's MvM mods.
- restart on mvm victory - restarts the current mission instead of changing level once a team wins in MvM mode
- No Truce - disables the forced truce on Valve's Halloween maps. This is a VScript file, must go in scripts/vscripts and be enabled with script_execute no_truce.nut in the config files for Eyeaduct and Ghost Fort.
- No Souls and Gargoyles - disables souls and ghost gargoyles from appearing. This is a VScript file, must go in scripts/vscripts and be enabled with script_execute no_souls.nut in server.cfg.
- Competitive Mode Voicelines - plays class-specific voice lines from competitive mode; up to personal preference. this is a mod, not a plugin; VPK file goes into the custom folder.
Performing Regular Maintenance
- Log on to your VDS with PuTTY
- Run the command sudo apt update && sudo apt-get full-upgrade -y
- If you are prompted to reboot the VDS, ensure no players are in your TF2 server and run sudo reboot at a convenient time. If your VDS is rebooted, remember to launch the TF2 server again once the VDS is running again.
- Repeat these steps at least once per week to ensure proper security patches are installed