How to Install a TF2 Server on a VPS
Written by Aaron "Aar" P.
Last updated March 1, 2023
Initialization
- Log in to your DigitalOcean account or sign up with my referral link
- Select a project and create a Droplet. I recommend the "Premium Intel/AMD" options, but you can get away with the basic 1c/1GB option.
- Select Ubuntu 22.04 LTS (or whichever LTS release is the latest)
- Select the server region closest to you/your players
- Enter a root password and commit it to memory
- Enter a hostname for your Droplet
- Create the Droplet
- Wait for the Droplet 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 you specified earlier
- 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 Droplet'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 libncurses5:i386 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libtinfo5:i386 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 login anonymous and press the Enter key
- Enter force_install_dir /hlserver/tf2 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 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
- 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 Droplet'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 Droplet 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 the dodbits TF2 server cfg generator website on your client computer
- Enter the settings you would like to use for your game server
- When prompted for a FastDL URL, enter http://x/fastdl/tf/ (replace x with your Droplet'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 Droplet in FileZilla and click View/Edit
- Locate sv_maxrate and change the following integer value to 0
- 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 disable Ghost Gargoyles from spawning.
- Save the file and click on FileZilla in your taskbar
- When prompted to re-upload the file with your changes, select Yes
- Right-click your Droplet's window in FileZilla and click Create empty file
- Name this file mapcycle.txt
- View/Edit mapcycle.txt with a list of maps you intend to run on the server, one per line
- Save your changes and re-upload the file when prompted
- Right-click your Droplet's window in FileZilla and click Create empty file
- Name this file motd.txt
- View/Edit motd.txt to show a message 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 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 Droplet's window in FileZilla and wait for the copy to finish
- Navigate to the SourceMod website and download the latest stable Linux release
- Extract the downloaded file with a program of your choice (I recommend 7-zip)
- Drag and drop the addons and cfg folders to your Droplet'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 Steam ID Finder 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"
- 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 Droplet'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 chmod 775 -R /var/www/html/
- Run sudo chgrp -R tfds /var/www/html/
- Open a connection to your Droplet 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/maps
Recommended SourceMod Plugins
- Steph's AntiCheat
- Jay's Backtrack Patch
- GroundFix
- TF2 Comp Fixes
- Fix ConTracker Animation Exploit
- Basic Votekick Immunity
- WaitingDoors
- Automatic Steam Update
- Unused Voicelines
- Competitive Mode Voicelines (this is a mod, not a plugin)
Performing Regular Maintenance
- Log on to your Droplet with PuTTY
- Run the command sudo apt update && sudo apt-get full-upgrade -y
- If you are prompted to reboot the server, ensure no players are in your TF2 server and run sudo reboot at a convenient time. If your server is rebooted, remember to launch the TF2 server again
- Repeat these steps at least once per week to ensure proper security patches are installed