Garry's Mod

Garry's Mod

79 évaluations
Setting Up a Dedicated Server on Linux
De Allotrope
An updated walkthrough of setting up and configuring a Garry's Mod server on Debian 7.
   
Récompenser
Ajouter aux favoris
Favoris
Retirer des favoris
Getting Started
Setting up a dedicated server on linux is a bit of a hassle if it is your first time attempting it. There are so many conflicting and outdated tutorials out there that it is difficult to figure out what exactly you need to do. If something goes wrong, is the fix that you found even going to help or is it outdated too?

I hope that through this guide I can help get you on the right track.

To start, you will need a server. You can run one on your own hardware, or you can find a paid hosting service. Personally, I use DigitalOcean[www.digitalocean.com] since their servers can be used for other things as well (handy for FastDL).

For this guide, I will be running 32-bit Debian 7. You can run the server on 64-bit, but you will need to move around some files. A quick Google search should get you the info you need, but for simplicity's sake, 32-bit will work just fine.

You will also need:
Users, Directories, and SteamCMD
Whether you are hosting locally or remotely, you will need to have console access to your server. I am using PuTTY as my SSH client to connect to my server using the login information provided by my host. You will need to do the same unless you have direct access to the machine the server will run on.



Enter the IP address of your sever in the highlighted area, make sure SSH is selected, and click open. You may get a Security Alert that says, "The server's host key is not cached in the registry." If you do, choose Yes. This just verifies that you trust the server you are connecting to.

When it connects it will open a new session and you should see a prompt like this:



Since my host provided me with the Root account information, I will login with that. Once you are logged in and you see this prompt, you are ready to make the user account to run the server (You can use root, but it's frowned upon. Be a rebel.):



Create a new user using adduser. I chose the username "gmod".
adduser gmod
You will need to enter a password and user information. Just press ENTER for the defaults.

We are done with the root account for now, end the session by typing exit, then press ENTER. Start up PuTTY again and use the same settings as before, however this time login as the user we created.



Now we need to create the folders for our server. I like to keep extra game content separate from the main server files, but your content folder can be anywhere you prefer. I will create these in our current directory (Home directory at login).
mkdir content gmodds Steam content/css
Once the directories are created, we need to install SteamCMD in the Steam folder.
cd Steam wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar -xvzf steamcmd_linux.tar.gz ./steamcmd.sh +login anonymous +quit
You will need to press ENTER to run the last command. If you take a listing of your /Steam directory (you should be in it now) by running ls, you should see this:



To install the dedicated server we need to run this command in the /Steam directory.
./steamcmd.sh +login anonymous +force_install_dir "PATH TO gmodds DIRECTORY" +app_update 4020 validate +quit
In my case it looks like this:
./steamcmd.sh +login anonymous +force_install_dir "/home/gmod/gmodds" +app_update 4020 validate +quit
This will login to SteamCMD anonymously, force the install directory to be my gmodds folder, install the Garry's Mod dedicated server files, validate them, then quit. Once you run it, be prepared to wait at this screen for a bit as it will start downloading what you need.



To check if everything is downloaded correctly, we need to see what is in our gmodds folder.
cd /home/gmod/gmodds ls
Everything seems to be there for me, hopefully your folder looks like this:



If it is empty, you may have installed it to the wrong directory. Go back and check what you entered as the force_install_dir path. If it went to the wrong location, delete the files there, edit that command with the correct path, and try again.
Starting the Server and Configuring Intro.
By this point, you should have a working, vanilla (no addons, no frills), Garry's Mod server. I believe that at this point, it is good to start it up,see that it runs, and that you can connect to it fine.

Start out by going to your ~/gmodds folder.
cd /home/gmod/gmodds
Here we will run the "srcds_run" script. This is what starts the server and it will accept additional commands about how to run the server. To run it, I will use this:
./srcds_run -console -game garrysmod +maxplayers 16 +map gm_construct


Upon running that command, you will see this:



The server is now up and running. If you close your PuTTY session, it will end, so keep that in mind. Go ahead and connect to the server in-game. Let's see if everything works. I connected through the console using connect server_ip_address.



Everything seems to be working well. I connected fine.



Disconnect and go back to your PuTTY session and enter quit. This will quit the server script and bring us back to the ~/gmodds directory.

Before I install more game content on my server, I want to cover how to configure some general settings. The file that we need to edit is called server.cfg. It is located in our servers /garrysmod/cfg directory.

We can edit this in two ways. The first is through a terminal based text-editor like nano. The second is by downloading the file, editing it in Notepad (etc.), and re-uploading it. This is where FileZilla[filezilla-project.org] comes in handy. I recommend using FileZilla for this since we can use it later to add content to the server.

To use FileZilla however, we need to have an FTP server set up.
Setting up FTP and FileZilla
FTP is handy have while configuring and adding content to your server. You can edit everything locally, then upload it in one big transfer.

(Hey! If you have SSH working, you may have SFTP enabled. Use your server/account info in FIlezilla just like you would below, but use port 22. It should work as well.)

For my server, I will use ftpd as the FTP service. To install it, login as root. You can use the gmod user account, but you will have to add it to the sudoers file.
aptitude install ftpd
It will ask if you would like to continue. Type y and press ENTER.



The FTP service is now set up for your server. You can exit the PuTTY session with exit.

Now on to using FileZilla[filezilla-project.org]. This part is easy.

Download FileZilla[filezilla-project.org], install it, and run it. You will see a window like this:



The highlighted areas are what we need to worry about. For the host, put your server IP. For Username, put your servers user account (not root). If you are following the tutorial, it should be "gmod". The password is the one you created for the "gmod" user. Enter this information, then click on Quickconnect.



In the bottom right section you should now see the contents of your home directory. You can click and drag to copy files to and from these folders to your local file system in the bottom left section. This also works with files on the Desktop or a File Explorer.
General Configuring
Now that we have FTP up and running we can start editing our configuration files.

The main file, server.cfg, handles variables such as your server's name, number of players, allowed number of props, etc.

Hopefully you are connected to your server in FileZilla and can see your files in the lower right section. If not, go back and follow through the previous section.

On to editing!

In FileZilla, browse to /home/gmod/gmodds/garrysmod/cfg, right-click on server.cfg and choose Edit.



This should download and open the blank server.cfg file in Notepad.

You can copy/paste the default settings I created below or write your own. This tool is handy if you are lazy.[gmod-servercfg.appspot.com]
hostname "My GMod Server" rcon_password "" sv_password "" sv_region 255 sv_lan 0 sv_logbans 1 sv_logecho 1 sv_logfile 1 sv_log_onefile 0 sv_noclipspeed 5 sv_noclipaccelerate 5 logging on //Sandbox Settings sbox_allownpcs 0 sbox_godmode 0 sbox_plpldamage 0 sbox_playergod 0 sbox_noclip 1 sbox_maxprops 250 sbox_maxragdolls 5 sbox_maxnpcs 5 sbox_maxballoons 25 sbox_maxeffects 25 sbox_maxdynamite 5 sbox_maxlamps 10 sbox_maxthrusters 250 sbox_maxwheels 50 sbox_maxhoverballs 50 sbox_maxvehicles 8 sbox_maxbuttons 50 sbox_maxsents 20 sbox_maxemitters 5 sbox_maxspawners 3 sbox_maxturrets 10 //Server Settings net_maxfilesize 30 sv_minrate 0 sv_maxrate 2500 decalfrequency 10 sv_maxupdaterate 66 sv_minupdaterate 10 //Execute ban files exec banned_ip.cfg exec banned_user.cfg

Paste the configuration into the server.cfg file, save, and close Notepad.



After closing Notepad, FileZilla will ask if you want to upload the edited file back to the server. Choose Yes.



This is all we will be editing for now. Feel free to close or minimize FileZilla, but we will be coming back to it later to mount game content in the next section.
Downloading and Mounting Game Content
This is the fun part. I personally had great deal of trouble with this. There were many conflicting tutorials over it and most of them showed how to write a script to update the game content, but not how to install the content manually. This would be fine if the scripts weren't specific to that one writer's set up and configuration.

So!

I will show you how to install the content manually. If you would like to make a script that updates them all in one swoop, go right ahead. There are other tutorials out there, I'm sure, but since I don't trust myself writing a script for that anyway, I feel that manual is best for all of us.

Start a new PuTTY session and log in to your sever using the gmod user account. Change the working directory to the Steam folder and run SteamCMD. I use /content/css to keep the game files separated and organized, change this when installing different game content.
cd Steam ./steamcmd.sh +force_install_dir "/home/gmod/content/css"
When you are at the Steam> prompt, enter:
login anonymous

Note: If you use login anonymous first and it gives you a "No Subscribtion" error when installing a game, login with your Steam account and try again.
login your_username
It will ask you for your password. It will most likely then deny you access and ask for your Steam Guard code. You will get an email with this in it. Enter the code and press ENTER. Keep in mind that this WILL log you out of Steam.

It will pause for a moment while it logs you into Steam on the server. If everything goes well, you will see Success. and it will go back to the Steam> prompt.

You are now ready to install game content into the content folder we created.

For this tutorial I will install Counter Strike: Source content, however you can install other game content by changing the app ID value to the desired game's ID. A list can be found here.

At the beginning of the tutorial we also created a folder called css inside the content folder. You will want to do the same for other games you install. You can name these folders however you like.

CS:S uses 232330 as its ID, so I will enter this to begin installing:
app_update 232330
Just like installing Garry's Mod, SteamCMD will download the files for Counter Strike: Source. This may take a while, go get yourself a drink and come back.



Once you see that the game was fully installed, type quit or press ctrl-c.

Let's check if the game files ended up where they were supposed to.
cd /home/gmod/content/css ls



Looks good to me.

We have our game content for Counter Strike downloaded and in place, now we need to tell our Garry's Mod server where this content is located. To do this we need to edit the mount.cfg file.

Open up FileZilla and go back to the /home/gmod/gmodds/garrysmod/cfg folder. Right-click on mount.cfg and choose to Edit.



Doing so will download and open the file in Notepad. Inside you will see an example of what we need to do. Unfortunately, what is shown is for a server hosted on a Windows system. Below is a copy of how I edited mine. Yours should look the same if you followed the tutorial exactly, but if you changed the location or name of anything, be sure to make your file reflect that.
// // Use this file to mount additional paths to the filesystem // DO NOT add a slash to the end of the filename // "mountcfg" { // "tf" "/home/gmod/content/tf2/tf" // "ep2" "/home/gmod/content/ep2/ep2" // "episodic" "/home/gmod/content/ep2/episodic" "cstrike" "/home/gmod/content/css/cstrike" }

I edited the examples as well, to match my file structure. When I install TF2, I will need to install it to the content/tf2 folder in my case.

Save the newly edited mount.cfg and close Notepad. FileZilla will ask if you want to upload the edited file. Choose Yes.



We are done with FileZilla for the rest of the tutorial, so feel free to close it. Or not, that's just, ...like, your choice man...

To test if we mounted everything correctly, let's start up the server again in PuTTY.
cd /home/gmod/gmodds ./srcds_run -console -game garrysmod +maxplayers 16 +map gm_construct

When you see VAC secure mode is activated., we're good to go. Load up Garry's Mod and connect to your server. Once joined, press tab to see your server's name. Hopefully it will be what you put in your config.cfg file.



That's the right name, so our config is working nicely. Now to check on Counter Strike, let's spawn some props from the game.



Perfect! If you get this working on your first try, I applaud you.[www.google.com]

Now you get to repeat that for other game content you want to add to your server. Fun stuff. The longest part is when you are waiting for the content to download so it's not too bad once you get that going.

Close your server by typing quit or pressing ctrl-c. I will show you how to install workshop content and use screen to keep the server running next.
Running the Server and the Workshop
Screen is an extremely handy tool if you are managing this server remotely. If not, it's still nice to have around, but not needed.

Start a new PuTTY session and log in as root. We are going to install screen.
aptitude install screen
It shouldn't prompt you with anything and will return you to where you were.



Once screen is installed close your PuTTY session and restart it. Login with the gmod user account.

Screen let's us run commands, scripts, and the like in a different terminal. They stay up even when the PuTTY session is closed and make it easy to manage multiple things at a time.

We will use screen to start our server.

First however, I want to create a new Collection of addons that I want installed onto my server. This collection is created by you in the Garry's Mod Workshop on Steam.

This is actually a step that is fairly well documented, so I will not cover it in this tutorial, but you can edit the example command I provide to match your information.

The wiki page for getting Workshop content on a dedicated server works and is fairly straight forward.[wiki.garrysmod.com]

Using screen to start the server without Workshop content:
cd /home/gmod/gmodds screen -A -m -d -S gmod ./srcds_run -console -game garrysmod +maxplayers 16 +map gm_construct
Using screen to start the server with Workshop content:
cd /home/gmod/gmodds screen -A -m -d -S gmod ./srcds_run -console -game garrysmod +maxplayers 16 +map gm_construct +host_workshop_collection XXXX -authkey YYYY
Replace the Xs with your collection ID and the Ys with the authorization key you created.

When you run the command it will seem like nothing happened. It created a screen in the background, named it gmod, and started the game server. Enter and run:
screen -r
This will load the screen we created. You should see your Garry's Mod server running as normal.



If you close this PuTTY session, the game will continue to run in the screen. If you need to get into the console again later, just login as normal and use the screen -r command.
Wrapping Up
I do think that is about it. There is much more I could cover, but I believe that the rest easy enough to find with a little Google-fu. If you do have questions about the content or need clarification, please respond in the comments below. I will try my best to point you in the right direction or revise my writing as needed. Any feedback is greatly appreciated.

I hope the process of setting up a server was less confusing to you than it was for me. This tutorial is my own documentation so that I have something to look back on for reference in the future. I do hope it helps.

Thank you for giving this tutorial a go and have fun with your server!

~Allotrope
58 commentaires
Allotrope  [créateur] 5 févr. 2021 à 18h24 
@brian Thanks for looking out. It was an address for a server created just for this guide 7 years ago (it's been 7 years!? am I OLD now?...). It was deactivated before posting.
Doc 5 févr. 2021 à 18h04 
oh no please don't tell me that is your real IP if it is someone could DDOS you
Kingtrax 14 oct. 2020 à 13h01 
Thanks! this was perfect!
Enchanting Mango 9 aout 2020 à 13h16 
You know I see a lot of people talk about screen but you could create a systemd service instead
VadimShadeWolf 6 déc. 2019 à 14h09 
Thanks, this guide helped me with mounting games content on server :ь
-⁧⁧AligatoR 28 mars 2018 à 19h33 
"ERROR! Failed to install app '4020' (Disc write failure)"

How do I fix this?
Zachy 24 nov. 2017 à 23h39 
Hello, I am having one issue.. I can't connect.. All port are fowarded, I tried port 25565 and the default port (27015) and I still can't seem to connect. I contacted my VPS host, and they said all of the ports were open, and to try flushing IPTables. So I did, nothing still.. No one can seem to connect remotely.
blu 30 juil. 2017 à 15h46 
@Allotrope Thanks for this wonderful guide! Nowhere else on the internet could I find anything remotely close to this! it helps me a ton, and I just wanted to express my gratitude for what you've done for everyone. Thanks, -Psych.
Nathan.Smiley 28 avr. 2017 à 6h52 
Ensuite j'entre comme demandé : -debug, ce qui donne :

[CODE]./srcds_run -console -game garrysmod +maxplayers 16 +map gm_construct -debug
[/code]

Voici ce que j'obtient :

[CODE]Using default binary: ./srcds_linux
Enabling debug mode
./srcds_run: ligne183: gdb : commande introuvable
WARNING: Please install gdb first.
goto http://www.gnu.org/software/gdb/
Server will auto-restart if there is a crash.
Failed to open dedicated_srv.so (/lib/i386-linux-gnu/i686/cmov/libm.so.6: version `GLIBC_2.15' not found (required by bin/dedicated_srv.so))
Add "-debug" to the ./srcds_run command line to generate a debug.log to help with solving this problem
[/code]
maxwell 27 avr. 2017 à 9h45 
Great! my server was working really cool now. But now my uTime addon is not working.