Skip to content

Instantly share code, notes, and snippets.

@Pinjontall94
Created March 29, 2026 10:57
Show Gist options
  • Select an option

  • Save Pinjontall94/0b566beee4a4d92f1b429dcee745815d to your computer and use it in GitHub Desktop.

Select an option

Save Pinjontall94/0b566beee4a4d92f1b429dcee745815d to your computer and use it in GitHub Desktop.
Vanilla Minecraft Unix Tutorial

Minecraft Server Unix Tutorial

Courtesy of/inspired by linuxize

0. Install dependencies

$ sudo apt update
$ sudo apt install git build-essential openjdk-21-jre-headless

1. Set up the minecraft user

$ sudo useradd --system --user-group --home-dir /opt/minecraft --shell /bin/bash minecraft
$ sudo su - minecraft
$ mkdir ~/{backups,tools,server}

Get and build mcrcon

$ cd ~/tools && git clone https://github.com/Tiiffi/mcrcon.git
$ cd mcrcon && gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c

Get the server jar

$ cd ~/server && wget https://piston-data.mojang.com/v1/objects/3872a7f07a1a595e651aef8b058dfc2bb3772f46/server.jar

2. Configuring the server

$ cd server
$ java -Xmx1024M -Xms512M -jar server.jar nogui

EULA

This will complain about the eula, so halt the server and accept it in eula.txt

$ vi server/eula.txt

Enter the following and save the file:

eula=true

RCON

Next, edit the server.properties with vi server/server.properties:

rcon.port=25575
rcon.password=SomeStrongPasswordDontUseThis
enable-rcon=true

3. Make the Minecraft Systemd Service

Exit minecraft user back to sudo user

$ exit

Write the minecraft service unit file /etc/systemd/system/minecraft.service:

[Unit]
Description=Minecraft Server
After=network.target

[Service]
User=minecraft
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui
ExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p SomeStrongPasswordDontUseThis stop

[Install]
WantedBy=multi-user.target

Reload the system services and run the new minecraft service

$ sudo systemctl daemon-reload
$ sudo systemctl enable --now minecraft

Adjust the firewall if necessary

$ sudo ufw allow 25565/tcp

4. Configure Backups

Switch to minecraft user (as before) and add the following to ~/tools/backup.sh:

#!/bin/bash

function rcon {
  /opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p SomeStrongPasswordDontUseThis "$1"
}

rcon "save-off"
rcon "save-all"
tar -cvpzf /opt/minecraft/backups/server-$(date +%F-%H-%M).tar.gz /opt/minecraft/server
rcon "save-on"

## Delete older backups
find /opt/minecraft/backups/ -type f -mtime +7 -name '*.gz' -delete 

Mark as executable with chmod +x ~/tools/backup.sh, then call crontab -e and add the following:

0 23 * * * /opt/minecraft/tools/backup.sh

5. Accessing the console

Call mcrcon with the -t flag to access the terminal

$ /opt/minecraft/tools/mcrcon/mcrcon -H localhost -P 25575 -p SomeStrongPasswordDontUseThis -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment