Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Installing a CSGO game server

profile picture
Author
Markus
Published
2019-04-05
Time to read
6 minutes reading time

Introduction

This article is about installing and configuring a CSGO game server on Linux systems.

Requirements

  • An x86 / x64 compatible system
  • Ubuntu 16.04 LTS
  • Installed steamcmd
  • CX21 server or better

Step 1 - Preparations

Creating the CSGO server folder, where the server files will be found:

mkdir /opt/csgo/
chown steamcmd:steamcmd /opt/csgo/

All commands should be executed as steamcmd user.

su --shell /bin/bash steamcmd

Step 2 - Installation

Download the server files via steamcmd:

steamcmd +login anonymous +force_install_dir /opt/csgo/ +app_update 740 +quit

Once the server has been downloaded, the settings can be set.

The CSGO server configuration file is located at /opt/csgo/csgo/cfg/server.cfg. Here you can edit and insert the sample configuration below.

// ************************************************************************** //
//     Counter-Strike: Global Offensive - server.cfg                          //
//     Version 240917                                                         //
// ************************************************************************** //
// .................................. Basic ................................. //

// Hostname - Name of the server.
hostname "SERVERNAME"

// RCON - remote console password.
rcon_password "ADMINPASSWORD"

// Server password - for private servers.
sv_password ""

// Email - Server admin email.
// Example: sv_contact "email@example.com"
sv_contact ""

// LAN mode - If set the server will not show on the internet.
// Default: sv_lan 0
sv_lan 0

// ............................. Server Logging ............................. //

// Enable log - Enables logging to file, console, and udp < on | off >.
// Recommended: log on
log on

// Log bans - Log server bans in the server logs.
// Default: sv_logbans 1
// Recommended: sv_logbans 1
sv_logbans 1

// Log echo - Display log information to the server console.
// Default: sv_logecho 1
// Recommended: sv_logecho 1
sv_logecho 1

// Log file - Log server information in the log file.
// Default: sv_logfile 1
// Recommended: sv_logfile 1
sv_logfile 1

// One file log - Log server information to only one file.
// Default: sv_log_onefile 0
// Recommended: sv_log_onefile 0
sv_log_onefile 0

// Server Hibernation
sv_hibernate_when_empty 1
sv_hibernate_ms 5

// ............................. Server Query ............................. //
// More info at: https://www.gametracker.com/games/csgo/forum.php?thread=91691
host_name_store 1
host_info_show 1
host_players_show 2

// ................................ Ban List ................................ //

// User ban - Server banlist based on user steam ID.
// Recommended: exec banned_user.cfg
exec banned_user.cfg

// IP ban - Server banlist based on user IP.
// Recommended: exec banned_ip.cfg
exec banned_ip.cfg

// Write ID - Writes a list of permanently-banned user IDs to banned_user.cfg.
writeid

// Write IP - Save the ban list to banned_ip.cfg.
writeip

Step 3 - Server administration

To manage (start, stop, update) the server, the following script is needed.

Most settings can be applied unchanged, only the entry GAMETOKEN has to be changed. A valid server Token must be deposited. Server tokens can be requested here: Steam Game Server Account Management

(On low-performance servers, the TICK entry should be reduced to 64.)

#!/bin/bash

################# SET VARs #################

DIR="/opt/csgo"
SCREENNAME="csgo"

GAMETOKEN=""
TICK=128
GAMETYPE=0
GAMEMODE=1
MAPGROUP="mg_bomb"
MAP="de_dust2"
MAXPLAYER=10

################# DO NOT MODIFY #################

DEAMON="srcds_run"
PARAMS="-game csgo -ip 0.0.0.0 -port 27015 +maxplayers $MAXPLAYER +map $MAP -tickrate $TICK +game_type $GAMETYPE +game_mode $GAMEMODE +mapgroup $MAPGROUP +sv_setsteamaccount $GAMETOKEN"

function start_server {
    if [[ `screen -ls | grep $SCREENNAME` ]]; then
        echo "The server is already running $SCREENNAME"
    else
        echo "Starte $SCREENNAME"
        if [ -d $DIR ]; then
           cd $DIR
           screen -d -m -S $SCREENNAME ./$DEAMON $PARAMS
        else
           echo "The server directory was not specified"
        fi
    fi
}

function stop_server {
    if [[ `screen -ls | grep $SCREENNAME` ]]; then
        echo -n "Stoppe $SCREENNAME"
        kill `screen -ls | grep $SCREENNAME | awk -F . '{print $1}'| awk '{print $1}'`
        echo " ... done."
    else
        echo "Could not find the screen $SCREENNAME"
    fi
}

function update_server {
    stop_server
    steamcmd +login anonymous +force_install_dir $DIR +app_update 740 +quit
    start_server
}

case "$1" in
start)
    start_server
;;

stop)
    stop_server
;;

restart)
    stop_server
    start_server
;;

update)
    update_server
;;

  *)
    echo "Usage: $0  (start / stop / update)"
esac

exit 0

For example, the script can be placed at /opt/steamcmd/csgo.sh.

After that, permissions must be granted to run the script:

chmod +x /opt/steamcmd/csgo.sh

Now a systemd service entry is needed. The entry is made at: /etc/systemd/system/csgo.service:

[Unit]
Description=Counter-Strike: Global Offensive Server (SRCDS)
After=local-fs.target network.target

[Service]
User=steamcmd
Group=steamcmd

ExecStart=/opt/steamcmd/csgo.sh start
ExecStop=/opt/steamcmd/csgo.sh stop
Type=forking

[Install]
WantedBy=multi-user.target

The entry just created must now be activated with the command systemctl daemon-reload. Now the CSGO server can be started or stopped with systemctl start csgo and systemctl stop csgo.

To set up the automatic server update, the following entry at crontab -e is required:

0 4 * * * systemctl stop csgo && su --shell /bin/bash steamcmd -c "/opt/steamcmd/csgo.sh update" && systemctl start csgo >/dev/null 2>&1

This entry would be executed every day at 4:00 AM.

Troubleshooting

Should there be any problems connecting to the screen, you will see the following error:

Cannot open your terminal '/dev/pts/0' - please check.

To resolve this, execute this command in the current session:

script /dev/null

Afterwards a connection with the screen session is possible again.

Conclusion

If you have followed the tutorial to this point, you have your own CSGO server that automatically updates itself.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue

Discover our

Dedicated Servers

Configure your dream server. Top performance with an excellent connection at an unbeatable price!

Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more