Quick start script

“I’m lazy and I need a script to do this for me” is my mantra, and it should be yours, too! Therefore, I made some scripts that automate the process below.

Check out this README file to see what command to run, in order to perform a one-line install on your server. Good luck!

Warning

This guide will not set up ufw, the default firewall of Linux servers. Consider turning it on if you’re going to deploy a public gaming server.

If you choose to use the script above, remember to verify the contents before letting it run on your server!

This guide (and script) will work best on Debian 10.

Initial server setup

Create a new administrator account:

adduser ideaman924

Update the server:

apt update && apt upgrade -y

Install sudo if your server doesn’t come with it:

apt install -y sudo

Give your user admin privileges:

usermod -aG sudo ideaman924

Install tmux and htop to make your server admin life easier:

apt install -y tmux htop

Those will be used for running the server processes in the background and for monitoring the health of the server.

Almost done! You need to log in as the new user, BUT do NOT log out from your current session yet. You need to verify some things before you actually log in as the new user.

Execute the following command:

nano /etc/ssh/sshd_config

Press Ctrl-W, and then type in PasswordAuthentication and then press Enter. You may need to retry this a couple of times to get to the correct line. If you see this:

PasswordAuthentication no

This means you logged in using SSH keys. This is extremely common if you used a VPS provider such as DigitalOcean and supplied your own SSH key.

If you see this:

# PasswordAuthentication no

How did you log in? Did you log in by supplying a password, or a key file? If using a key file, try logging into the server in a separate session with a password this time. If it fails, then you have password authentication disabled, which is exactly what you want (it’s secure!)

If you see this:

PasswordAuthentication yes

This means you can log into your new user account using your password. This is not really secure so it’s not recommended. Generate an SSH key and disable password authentication.

We need to change the default SSH port. Change it to something random and high, like 30724. Obviously, choose a random port number that isn’t bigger than 65535 and isn’t smaller than 1000!

Port 30724

Press Ctrl-O, and then Enter to save, and then press Ctrl-X to exit nano. Now, if you have SSH-key authentication, type the following commands:

cp -r ~/.ssh /home/ideaman924
chown -R ideaman924:ideaman924 /home/ideaman924/.ssh

Make sure to change the username if you have done so while creating the new admin acocunt.

You don’t have to do anything if you have password-based authentication, but I really recommend turning it off because passwords are easy to crack.

Now try logging in as the new user. If you are successful, it’s time to disable root logins. (You don’t have to do this either.) Edit the file and change PermitRootLogin to no. Reboot the server to reflect the changes (or just restart the SSH daemon service).

Log in as the new user. Congratulations! You have your server set up. Now it’s time to set up the game processes on the server.

Minecraft

We need to first install Java:

sudo apt install -y openjdk-11-jre-headless

Let’s create a directory to contain all of our Minecraft files:

mkdir minecraft
cd minecraft

Now, we need to download the actual server binary. If you want to download vanilla, follow this link. For PaperMC, follow this link. To get the raw download URL, right-click on the URL or build number and click on “Copy Link Address.”

Paste it in the code block below:

wget https://package/url/here -O minecraft_server.jar

So for example, I would run:

wget https://papermc.io/api/v1/paper/1.15.2/90/download -O minecraft_server.jar

To start the server, we need a script. Make a file called start.sh and paste in the contents below:

#!/bin/bash

RAM_MINIMUM=256
RAM_MAXIMUM=512

java -Xms"$RAM_MINIMUM"m -Xmx"$RAM_MAXIMUM"m -jar minecraft_server.jar

Experiment with the RAM values as needed. A good rule of thumb is about 1 GB for about 4 players,. 2 GB for about 6 players, and 4 GB for about 10 players.

Now, make the script executable:

chmod +x start.sh

When you first run the server, it may ask you to accept an EULA. Simply edit the eula.txt file and change the value to yes. You’re done! Start the server like so:

./start.sh

You may need to adjust server properties in server.properties. I recommend setting up proper whitelisting.

Factorio

Download and extact the server binary:

wget -O factorio.tar https://www.factorio.com/get-download/0.17.74/headless/linux64
tar -xvf factorio.tar

(If the unextract command fails, run sudo apt install xz-utils)

Go into the factorio/ directory. Copy over game saves if you have any. You need to copy the following if you want to play with a previous save:

config/
saves/
achievements.dat
player-data.json
server-adminlist.json

Enter tmux and run;

./bin/x64/factorio --start-server-load-latest --server-settings ./config/server-settings.json

This command should load the latest game save, referencing the configuration file.