So, with credit to the Factorio wiki and cbednarski's helpful gist, I managed to eventually setup a Factorio headless server. Although, I thought the process could be nailed down/simplified to be a bit more 'tutorialised' and also to document how I got it all working for my future records.
The specific distro/version I'm using for this guide being Ubuntu Server 16.04.1 LTS
. Although, that shouldn't matter, as long as your distro supports systemd
(just for this guide, not a Factorio headless requirement, although most distros use it as standard now).
The version of Factorio I shall be using is 0.14.20
, although should work for any version of Factorio 0.14.12
and higher.
Just a note to newcomers: If there are any issues with the installation steps, people in the comments are doing a good job at mentioning steps required by newer installations. I don't really play anymore and haven't setup or managed a Factorio server in years, so I'll advise if something isn't working to check the comments and forks. Much love <3
If you prefer a simple, automated setup, Bisa has a really handy init script that will do most of the work for you!
I'm very much into Docker these days, in which there is a brilliant container setup and ready for this if you wish to use that instead.
- *nix distro, setup and ready to go
- The UDP port used for Factorio, default
34197
, forwarded through your router. I won't go into how to do this here as it's a seperate tutorial in of itself, but you can easily Google "{routers model/manufacturer} port forward" and find the desired results. - Optional - Setup SSH for remote access, this may be handy if you wish to upload/download saves via
scp
(?). If you would like to do this, it's recommended that you disable password login and use SSH keys. - Tip - If you ever miss
sudo
from the beginning of a command,sudo !!
will repeat it, but elevated. - That's it!
With it being a fresh installation, as with any OS, make sure to update your system. Run sudo apt update && sudo apt full-upgrade
. This will first check the relevant repo's for package updates, then run the update process.
If your server is running from behind your edge router/firewall, then enabling the firewall isn't a necessary step. So skip to the next step if you don't want to enable it.
I like to enable the firewall before getting started on setup, just personal preference. This is as simple as sudo ufw enable
. UFW being Uncomplicated Firewall, in which it really is!
Let's allow Factorio through on its default port (or a port of your chosing), sudo ufw allow 34197/udp
. You may also want to allow SSH connections through at this point, if you are using it.
As this is an internet facing server, you may want to install and configure something like fail2ban
to help with repeated non-authorised login attempts, but that is up to you.
I'm going to be working out of my home directory, just for simplicity. Let's grab the headless server from Factorio's download site via wget
onto the server.
wget -O factorio_headless.tar.gz https://www.factorio.com/get-download/0.14.20/headless/linux64
Unfortunately, the url for the download isn't static, so you'll have to change the version in the url to what version you require (stable or experimental). Easiest way to find out the url is to go to the Factorio server download page and find the url from the link provided under the version number.
Also, as they redirect download requests, wget
will not name the file correctly. The easiest way to rectify it is to manually set the file name using the -O
flag and manually providing the file name as used in the example above.
Wait for the file to download before proceeding.
Factorio runs out of the /opt
directory, a directory resevered in UNIX for non-default software installation.
So before extracting the headless archive, lets change our working directory, cd /opt
.
Now its time to extract the headless archive, sudo tar -xzf ~/factorio_headless.tar.gz
. The -xzf
flags are basically; ex
tract a gz
ipped archive f
ile. This will extract the downloaded archive to your current directory, and should have created a Factorio folder. You can check that /opt/factorio
exists by running ls
(?), and seeing if the factorio
directory is listed, as we are working out of /opt
already.
Just for the sake of keeping things tidy, I'd also delete the downloaded archive rm ~/factorio_headless.tar.gz
, as we are now finished with it.
If you wish to add any mods or saves, you can do so by first creating the mods
and saves
directories within /opt/factorio
. sudo mkdir /opt/factorio/saves
and sudo mkdir /opt/factorio/mods
should achieve this, then you may copy the save & mod archives into the relevant folders.
As you don't want Factorio running as root, let's setup a user that it can run under. The user won't need a lot of functionality, as it's only going to be running Factorio and won't need to be logged into, so let's provide some flags to create a really basic user:
sudo adduser --disabled-login --no-create-home --gecos factorio factorio
The above command will add a user, not setting a password --disabled-login
, without creating a home directory in /home
--no-create-home
, without asking for user information --gecos
, create user factorio
and add them/create the group factorio
.
Now that the new user is created, we need to make it the owner of the Factorio directory so that it can access and perform operations within it, sudo chown -R factorio:factorio /opt/factorio
. The -R
flag being recursive.
Factorio headless, as of 0.14.12, requires a JSON formatted config file. They provide an example one to get you started, in which can be copied and then edited to suit your requirements.
First, lets change directory cd /opt/factorio/data
where the server-settings.example.json
config file is located, it's not necessary, but just the way I do things. Now to make a copy of the config file under its working name sudo cp server-settings.example.json server-settings.json
and then edit it with a text editor of your choice, I like nano as its easy sudo nano server-settings.json
.
The configuration is fairly straight forward and mirrors that of the GUI when setting up a server via the standard edition of Factorio. Here is the configuration reference. Configure it as you wish, save, exit and proceed onto the next step.
So, we want Factorio to run as a service. So lets create a new service for Factorio within the systemd service scheduler. Again, I like nano as its easy, but any text editor will do sudo nano /etc/systemd/system/factorio.service
. The service should contain the following:
[Unit]
Description=Factorio Headless Server
[Service]
Type=simple
User=factorio
ExecStart=/opt/factorio/bin/x64/factorio --start-server /opt/factorio/saves/{save_file}.zip --server-settings /opt/factorio/data/server-settings.json
Change the {save_file}
for the file name of your save. You may also want to swap out --start-server /opt/factorio/saves/{save_file}.zip
for --start-server-load-latest
, which will automatically pull through the latest version of your world across manual and auto saves. If you wish to look at more parameters, there is more information on the Factorio multiplayer wiki.
Save the file and exit. Time to start the service and see if our setup has worked!
Firstly, reload the available service daemons systemctl daemon-reload
, now start the newly created service systemctl start factorio
and see if it's running systemctl status factorio.service
. That is the output from the Factorio server, any errors or configuration issues will present themselves here if you ever need to debug.
If you do make any configuration changes, you'll need to restart the service sudo systemctl restart factorio.service
.
That's it! You should now have a working Factorio server. Head over to your client and under "Multiplayer" > "Connect to a server", provide your address that you set it up against (and port if you changed it from the default) and play spend hours labouring over tiny details to maximize efficiency!
- How to upgrade
- How to create/scp your own save (re-apply chown)
With a quick shout out to dillinger.io for making MD editing a more pleasant experience...
Oh man, I never got notified of the comments... below are some updated guides that I found as I am far out of the loop now, haven't touched Factorio in months.