How to Install a TF2 Server on a VPS


Written by Aaron "Aar" Pearson
Last updated November 9, 2024

This guide is meant to be used in conjunction with this video.

Initialization

  1. Log in to your Hetzner account or sign up with my referral link. (This guide previously used DigitalOcean)
  2. Click Continue and then click Sign Up on the next page
  3. 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.
  4. Navigate to https://console.hetzner.cloud/projects and create a new project
  5. Navigate into your project, select Servers, then click Add Server
  6. Select the server region closest to you/your players
  7. Select Ubuntu 24.04 LTS (or whichever LTS release is the latest). This must SPECIFICALLY be an LTS release.
  8. 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.)
  9. Select "Public IPv4" and "Public IPv6" networking options
  10. Enter a hostname for your VDS
  11. Create the VDS
  12. Wait for the VDS to initialize, and copy its IP Address once it finishes
  13. Install PuTTY on your computer
  14. Paste the IP Address into PuTTY
  15. Enter "root" as the username, press enter
  16. Enter the root password that was sent to you via email by Hetzner
  17. After logging in, enter the root password again
  18. Set up a new password and enter it again when prompted
  19. Run useradd tfds (replace tfds with your desired user name every time tfds is mentioned)
  20. Run passwd tfds to set a password (ideally different from the root password set earlier)
  21. Run usermod -aG sudo tfds
  22. Run sudo usermod --shell /bin/bash tfds
  23. Run sudo mkdir /home/tfds
  24. Run sudo chown tfds /home/tfds
  25. Close PuTTY and reopen it. Re-enter your VDS's IP
  26. Enter the username you specified
  27. Enter your password
  28. Run sudo nano /etc/ssh/sshd_config
  29. Press the down arrow key until you find the text PermitRootLogin yes
  30. Change PermitRootLogin yes to PermitRootLogin no using your keyboard
  31. Press Ctrl + X, then Y, then Enter
  32. Run sudo service sshd restart
  33. Run sudo apt update and then run sudo apt upgrade -y
  34. Close PuTTY and reopen it and sign in as the tfds user


Install SteamCMD and TF2 Dedicated Server

  1. Run sudo mkdir /hlserver
  2. Run sudo chmod 775 /hlserver
  3. Run sudo chown tfds /hlserver to get permissions
  4. Run cd /hlserver
  5. Run sudo dpkg --add-architecture i386
  6. Run sudo apt update
  7. Run sudo apt install lib32z1 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 -y
  8. Run wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
  9. Run tar zxf steamcmd_linux.tar.gz
  10. Run nano tf2_ds.txt
  11. Enter force_install_dir /hlserver/tf2 and press the Enter key
  12. Enter login anonymous and press the Enter key
  13. Enter app_update 232250 and press the Enter key
  14. Enter quit
  15. Press Ctrl + X, then Y, then Enter
  16. Run nano update.sh
  17. Enter ./steamcmd.sh +runscript tf2_ds.txt
  18. Press Ctrl + X, then Y, then Enter
  19. Run sudo chmod +x steamcmd.sh update.sh
  20. 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

  1. Run mkdir /home/tfds/.steam
  2. Run ln -s /hlserver/linux64 /home/tfds/.steam/sdk64
  3. Run ln -s /hlserver/linux32 /home/tfds/.steam/sdk32
  4. Run nano tf.sh
  5. Enter #!/bin/sh and press the Enter key
  6. 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
  7. Visit this wiki entry to see additional parameters and use +maxplayers 24 +map ctf_2fort +sv_pure 0 as a base
  8. (Use srcds_run_64 in place of srcds_run to use a 64-bit server executable. This will likely break SourceMod plugin compatibility.)
  9. Press Ctrl + X, then Y, then Enter
  10. Run sudo chmod +x tf.sh
  11. Run ./tf.sh to start the game server and wait for files to verify and for the map to start
  12. Open Team Fortress 2 on your client computer and enter the console command connect x (replace x with VDS's IP)
  13. Verify that you successfully loaded into the map you specified in tf.sh
  14. Press Ctrl + C in PuTTY to terminate the game server session


Additional Setup and Customization

  1. Run sudo ufw allow 22
  2. Run sudo ufw allow 80
  3. Run sudo ufw allow 27015
  4. Run sudo ufw enable
  5. Install FileZilla on your computer (watch out for sponsored offers in the default installer)
  6. Connect to your VDS by entering its IP, your username and password, followed by port 22 for sFTP
  7. Enter the hlserver, tf2, and tf folders
  8. Enter the cfg folder
  9. Visit avi12's TF2 server cfg generator website on your client computer
  10. Enter the settings you would like to use for your game server
  11. When prompted for sv_maxrate, enter 0
  12. When prompted for net_chan_limit_msec, enter 128. Increase this number to 192 or decrease it to 0 (to disable the feature) if legitimate players are frequently kicked with "processing time exceeded."
  13. When prompted for sv_downloadurl, enter http://x/fastdl/tf/ (replace x with your VDS's IP)
  14. Download your server.cfg file
  15. Drag and drop the server.cfg file into FileZilla as shown in my video
  16. Right-click on server.cfg from your VDS in FileZilla and click View/Edit
  17. 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).
  18. OPTIONAL: Make another new line and enter sm_cvar tf_halloween_gift_lifetime 0 to prevent Ghost Gargoyles from spawning.
  19. When prompted to re-upload the file with your changes, select Yes
  20. Right-click your VDS's window in FileZilla and click Create empty file
  21. Name this file mapcycle.txt
  22. View/Edit mapcycle.txt with a list of map filenames you intend to run on the server, one per line (ex. "cp_gravelpit_snowy")
  23. Save your changes and re-upload the file when prompted
  24. Right-click your VDS's window in FileZilla and click Create empty file
  25. Name this file motd.txt
  26. View/Edit motd.txt to show a message (or URL) to users when they connect to your server
  27. Save your changes and re-upload the file when prompted


Installing SourceMod

  1. Select the .. folder in FileZilla to go up one directory and return to /hlserver/tf2/tf
  2. Navigate to the Metamod:Source website and download the latest stable Linux build
  3. Extract the downloaded file with a program of your choice (I recommend 7-Zip)
  4. Drag and drop the addons folder to your VDS's window in FileZilla and wait for the copy to finish
  5. Navigate to the SourceMod website and download the latest stable/dev Linux build (some plugins require dev builds)
  6. Extract the downloaded file with a program of your choice (I recommend 7-Zip)
  7. Drag and drop the addons and cfg folders to your VDS's window in FileZilla and wait for the copy to finish
  8. Navigate to the addons folder, the sourcemod folder, and the configs folder
  9. Right-click on admins_simple.ini and click View/Edit
  10. Visit steamid.io and copy your steamID
  11. Paste your steamID on the last line of admins_simple.ini, surrounded by quotes, and press the Tab key
  12. Enter "99:z" to give yourself full root access
  13. Save the file and re-upload when prompted by FileZilla


Keeping the Server Running

  1. Re-open PuTTY
  2. Run screen -S tf2 to create a new session for TF2 that persists
  3. Run cd /hlserver
  4. Run ./tf.sh
  5. Press Ctrl + A and then the D key to disconnect from the screen session
  6. Run screen -r to reconnect to the session, and remember this information for later
  7. You will need to repeat this set of steps after every server reboot


Testing the TF2 Server Again

  1. Open Team Fortress 2 on your local computer
  2. Run the command connect x (replacing x with your VDS's IP)
  3. Run the command sm in the console and check for errors
  4. Use sm_rcon to run commands on the server's command line


Hosting Workshop Maps

  1. Enter the command changelevel workshop/xxxxxx in your server's command line (replace xxxxxx with the ID of the Workshop map)
  2. You can also use this syntax in mapcycle.txt


Setting up Locally-Hosted Maps

  1. Run sudo apt-get install apache2
  2. Run sudo systemctl restart apache2
  3. Run sudo chmod 775 -R /var/www/html/
  4. Run sudo chgrp -R tfds /var/www/html/
  5. Open a connection to your VDS in FileZilla
  6. Navigate to the var, www, and html folders
  7. Create a new folder titled fastdl and enter it
  8. Create a new folder titled tf and enter it
  9. Create a new folder titled maps and enter it
  10. Place bz2-compressed versions of maps you would like to host in this folder
  11. 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 the players win 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

  1. Log on to your VDS with PuTTY
  2. Run the command sudo apt update && sudo apt-get full-upgrade -y
  3. 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.
  4. Repeat these steps at least once per week to ensure proper security patches are installed