How to set up a FiveM server on Linux: artifacts, systemd and ufw

Run a FiveM server on Ubuntu or Debian: download the artifact, extract it, start run.sh with txAdmin or server.cfg, keep it alive with screen or systemd, open ports with ufw.

You have a Linux VPS (Ubuntu or Debian) and want a FiveM server on it. The process is short: get the server files, start them, keep them running, and open the ports. This guide covers each step with commands you can copy.

Before you start

You need a license key from portal.cfx.re, see the license key error if you have not made one yet. Install the tools you will use:

bash
sudo apt update
sudo apt install -y wget git xz-utils screen

Create a separate user, so the server does not run as root:

bash
sudo adduser fivem
sudo su - fivem

Everything below is done as that user.

Download the artifact

The server program ("artifacts") for Linux comes from Cfx.re:

text
https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/

Open that page, pick the recommended build, and copy the link to fx.tar.xz. Then:

bash
mkdir -p ~/fivem/server
cd ~/fivem/server
wget https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/<build>/fx.tar.xz
tar xf fx.tar.xz
rm fx.tar.xz

Replace <build> with the path you copied. After extracting you should see a run.sh in the folder.

Get the server data

The "server data" is where your server.cfg and your resources live. The Cfx.re base resources are on GitHub:

bash
cd ~/fivem
git clone https://github.com/citizenfx/cfx-server-data.git server-data

Create the config in server-data/server.cfg:

cfg
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"

sv_hostname "My FiveM server"
sv_maxclients 32
sv_licenseKey "cfxk_your_key_here"

ensure mapmanager
ensure chat
ensure spawnmanager
ensure sessionmanager
ensure basic-gamemode
ensure hardcap

Start it: txAdmin or plain

With txAdmin (recommended). Run run.sh without arguments. txAdmin starts, prints a PIN and a web address, and you finish the setup in the browser on port 40120:

bash
cd ~/fivem/server
bash run.sh

txAdmin keeps its data in a txData folder, usually in the folder you started it from, so always start it from the same place. In the panel you can use a recipe to deploy a base server, or point it at the server-data folder you cloned.

Without txAdmin. Start from the server-data folder and pass the config:

bash
cd ~/fivem/server-data
bash ../server/run.sh +exec server.cfg

You get the plain console in your terminal. Press Ctrl+C to stop it.

If you lose your txAdmin password later, see txAdmin forgot password.

Keep it running with screen

The quick way to keep the server alive after you disconnect from SSH is screen:

bash
screen -S fivem
cd ~/fivem/server
bash run.sh

Detach with Ctrl+A, then D. The server keeps running. Reattach later:

bash
screen -r fivem

This works, but nothing restarts the server if the machine reboots or the process dies.

Keep it running with systemd

A systemd service starts the server at boot and restarts it after a crash. Create the file as root (or with sudo):

bash
sudo nano /etc/systemd/system/fivem.service
ini
[Unit]
Description=FiveM server
After=network.target

[Service]
Type=simple
User=fivem
WorkingDirectory=/home/fivem/fivem/server
ExecStart=/bin/bash /home/fivem/fivem/server/run.sh
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

This starts txAdmin, which manages the game server itself. Then enable and start it:

bash
sudo systemctl daemon-reload
sudo systemctl enable fivem
sudo systemctl start fivem

Useful commands:

bash
sudo systemctl status fivem
sudo journalctl -u fivem -f
sudo systemctl restart fivem

The journalctl line shows the live output, which is where you read the txAdmin PIN on first start.

Tip: with systemd there is no interactive console. Run it with txAdmin and use the txAdmin live console, which is the reason to prefer txAdmin on Linux.

Open the ports with ufw

bash
sudo ufw allow OpenSSH
sudo ufw allow 30120/tcp
sudo ufw allow 30120/udp
sudo ufw allow 40120/tcp
sudo ufw enable

Allow SSH before you enable ufw, or you lock yourself out. The 40120 rule is for txAdmin: if you only manage the server from the VPS through an SSH tunnel, you can leave it out. Also check your hosting provider's own firewall panel. The full network check, including testing with F8 connect, is in FiveM server not showing: port forwarding and firewall.

Updating later

To update, stop the service, replace the contents of ~/fivem/server with a new artifact, and start it again. Your txData and server-data stay in place. The details are in updating FiveM server artifacts.

Checklist

Symptom Fix
No run.sh after download Extract with tar xf fx.tar.xz inside the server folder
Need the txAdmin panel Run bash run.sh with no arguments, open port 40120
Start without txAdmin bash ../server/run.sh +exec server.cfg from server-data
Server stops when SSH closes Use screen -S fivem or a systemd service
Should start on boot systemctl enable fivem
Players cannot connect Allow 30120 tcp and udp in ufw and in the host's firewall

Quick answers

How do I run a FiveM server on Linux?

Download the Linux artifact from runtime.fivem.net, extract it with tar xf fx.tar.xz, and start run.sh. Run it without arguments for txAdmin, or with +exec server.cfg to start the server directly.

How do I keep the FiveM server running after I close SSH?

Run it inside screen or tmux, or better, as a systemd service that starts on boot and restarts after a crash.

Should I run FiveM as root?

No. Create a normal user for it. It limits the damage if a resource is compromised, and txAdmin itself will warn you when it runs as root.

Scripts that skip this problem

Mic PhoneA foldable phone that unfolds into a tablet and carries onto a player's real phone.View script →Advanced BoostingTablet-driven vehicle boosting: contracts from class D to S+, crews and a live queue.View script →Crypto MiningBuy a warehouse, build rigs part by part and mine coins on a market that moves.View script →

Keep reading