How to Install a TF2 Server on a VPS


Written by Aaron "Aar" P.
Last updated June 17, 2020

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

Initialization

  1. Log in to your DigitalOcean account or sign up with my referral link
  2. Select a project and create a Droplet
  3. Select Ubuntu 20.04 LTS (or whichever LTS release is the latest)
  4. Select the server region closest to you/your players
  5. Enter a root password and commit it to memory
  6. Enter a hostname for your Droplet
  7. Create the Droplet
  8. Wait for the Droplet to initialize, and copy its IP Address once it finishes
  9. Install PuTTY on your computer
  10. Paste the IP Address into PuTTY
  11. Enter "root" as the username, press enter
  12. Enter the root password you specified earlier
  13. Run useradd tfds (replace tfds with your desired user name every time tfds is mentioned)
  14. Run passwd tfds to set a password (ideally different from the root password set earlier)
  15. Run usermod -aG sudo tfds
  16. (OPTIONAL: Run sudo mkdir /home/tfds and sudo chgrp tfds -R /home/tfds)
  17. Close PuTTY and reopen it. Re-enter your Droplet's IP
  18. Enter the username you specified
  19. Enter your password
  20. Run sudo usermod --shell /bin/bash tfds
  21. Run sudo nano /etc/ssh/sshd_config
  22. Press the down arrow key until you find the text PermitRootLogin yes
  23. Change PermitRootLogin yes to PermitRootLogin no using your keyboard
  24. Press Ctrl + X, then Y, then Enter
  25. Run sudo service sshd restart
  26. Run sudo apt-get update -y and then run sudo apt-get full-upgrade -y


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-get update
  7. Run sudo apt-get install lib32z1 libncurses5:i386 libbz2-1.0:i386 lib32gcc1 lib32stdc++6 libtinfo5:i386 libcurl3-gnutls:i386
  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 login anonymous and press the Enter key
  12. Enter force_install_dir /hlserver/tf2 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
  20. Run sudo chmod +x update.sh
  21. Run ./update.sh and wait for the installation to finish
  22. (If the download errors out, simply run ./update.sh again to resume from where it left off)


Testing TF2 Dedicated Server

  1. Run nano tf.sh
  2. Enter #!/bin/sh and press the Enter key
  3. 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
  4. Visit this guide to see additional parameters or use +maxplayers 24 +map ctf_2fort +sv_pure 0 as a base
  5. Press Ctrl + X, then Y, then Enter
  6. Run sudo chmod +x tf.sh
  7. Run ./tf.sh to start the game server and wait for files to verify and for the map to start
  8. Open Team Fortress 2 on your client computer and enter the console command connect x (replace x with Droplet's IP)
  9. Verify that you successfully loaded into the map you specified in tf.sh
  10. 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 Droplet 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 the dodbits 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 a FastDL URL, enter http://x/fastdl/tf/ (replace x with your Droplet's IP)
  12. Download your server.cfg file
  13. Drag and drop the server.cfg file into FileZilla as shown in my video
  14. Right-click on server.cfg from your Droplet in FileZilla and click View/Edit
  15. Locate sv_maxrate and change the following integer value to 0
  16. Make a new line at the bottom of the file and enter sm_cvar nb_update_frequency 0
  17. Save the file and click on FileZilla in your taskbar
  18. When prompted to re-upload the file with your changes, select Yes
  19. Right-click your Droplet's window in FileZilla and click Create empty file
  20. Name this file mapcycle.txt
  21. View/Edit mapcycle.txt with a list of maps you intend to run on the server, one per line
  22. Save your changes and re-upload the file when prompted
  23. Right-click your Droplet's window in FileZilla and click Create empty file
  24. Name this file motd.txt
  25. View/Edit motd.txt to show a message to users when they connect to your server
  26. Save your changes and re-upload the file when prompted


Installing SourceMod

  1. Select the .. folder in FileZilla to 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 Droplet's window in FileZilla and wait for the copy to finish
  5. Navigate to the SourceMod website and download the latest stable Linux release
  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 Droplet'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 Steam ID Finder 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"
  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 computer
  2. Run the command connect x (replacing x with your Droplet'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 chmod 775 -R /var/www/html/
  3. Run sudo chgrp -R tfds /var/www/html/
  4. Open a connection to your Droplet in FileZilla
  5. Navigate to the var, www, and html folders
  6. Create a new folder titled fastdl and enter it
  7. Create a new folder titled tf and enter it
  8. Create a new folder titled maps and enter it
  9. Place bz2-compressed versions of maps you would like to host in this folder
  10. Place bsp versions of maps you would like to host in /hlserver/tf2/tf/maps


Performing Regular Maintenance

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