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:
sudo apt update
sudo apt install -y wget git xz-utils screenCreate a separate user, so the server does not run as root:
sudo adduser fivem
sudo su - fivemEverything below is done as that user.
Download the artifact
The server program ("artifacts") for Linux comes from Cfx.re:
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:
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.xzReplace <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:
cd ~/fivem
git clone https://github.com/citizenfx/cfx-server-data.git server-dataCreate the config in server-data/server.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 hardcapStart 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:
cd ~/fivem/server
bash run.shtxAdmin 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:
cd ~/fivem/server-data
bash ../server/run.sh +exec server.cfgYou 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:
screen -S fivem
cd ~/fivem/server
bash run.shDetach with Ctrl+A, then D. The server keeps running. Reattach later:
screen -r fivemThis 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):
sudo nano /etc/systemd/system/fivem.service[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.targetThis starts txAdmin, which manages the game server itself. Then enable and start it:
sudo systemctl daemon-reload
sudo systemctl enable fivem
sudo systemctl start fivemUseful commands:
sudo systemctl status fivem
sudo journalctl -u fivem -f
sudo systemctl restart fivemThe 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
sudo ufw allow OpenSSH
sudo ufw allow 30120/tcp
sudo ufw allow 30120/udp
sudo ufw allow 40120/tcp
sudo ufw enableAllow 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 →