DGuard

Minecraft server on Linux: a VPS setup with autostart

On an Ubuntu or Debian VPS a Minecraft server takes about half an hour: Java from the Amazon Corretto repository, a dedicated user without root rights, Paper, the console in tmux and a systemd unit that brings the server back after a reboot and shuts it down cleanly with stop.

The DGuard team7 min read

In short: install Java (25 for Paper 26.x, 21 for 1.21.x), create a minecraft user, put Paper in /opt/minecraft, run it once and accept the EULA. Then keep the console in tmux and let systemd handle autostart — the server survives a reboot of the machine and shuts down through stop, without losing unsaved chunks. The last step is opening the game port in the firewall.

What you need

  • A VPS or dedicated server with Ubuntu or Debian and SSH access with sudo. How to pick the machine: hosting or VPS.
  • A free TCP port for the game — 25565 by default — and the SSH port.
  • An idea of how much memory to give the server: Paper advises leaving the OS about 1–1.5 GB spare; more in how much RAM a server needs.

Step 1. The system and a dedicated user

Update the packages and create a system user for the server. A server started as root gets rights over the whole machine — and so does every plugin it loads. A dedicated user limits the damage if a plugin turns out malicious or vulnerable.

terminal
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y tmux curl jq
sudo adduser --system --group --home /opt/minecraft minecraft

Step 2. Java

Paper's docs install Java from the Amazon Corretto repository. Paper 26.1 and newer needs Java 25, 1.20–1.21.11 needs Java 21. Skip packages with a headless suffix: they lack dependencies Paper needs.

Amazon Corretto 25 on Debian and Ubuntu — following Paper's guide
sudo apt-get install -y ca-certificates apt-transport-https gnupg wget
wget -O - https://apt.corretto.aws/corretto.key | sudo gpg --dearmor -o /usr/share/keyrings/corretto-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corretto.aws stable main" | sudo tee /etc/apt/sources.list.d/corretto.list
sudo apt-get update
sudo apt-get install -y java-25-amazon-corretto-jdk libxi6 libxtst6 libxrender1
java -version   # the first line should start with openjdk 25

For a 1.21.x server, install java-21-amazon-corretto-jdk from the same repository. The full Java table is in how to make a Minecraft server.

Step 3. Paper and the first start

Download a build from Paper's downloads page or with a script through PaperMC's downloads API. The API requires a User-Agent header naming your software and a contact — it rejects curl's default header.

the latest stable Paper build through the API (run in /opt/minecraft as the minecraft user)
VERSION=1.21.11
UA="my-server-setup (admin@example.com)"   # PaperMC's API wants your name and a contact
URL=$(curl -s -H "User-Agent: $UA" \
  "https://fill.papermc.io/v3/projects/paper/versions/$VERSION/builds" \
  | jq -r 'map(select(.channel == "STABLE")) | .[0] | .downloads."server:default".url')
curl -H "User-Agent: $UA" -o paper.jar "$URL"
/opt/minecraft/start.sh
#!/bin/sh
cd /opt/minecraft
exec java -Xms4G -Xmx4G -jar paper.jar --nogui
  1. 1

    Make the script executable

    sudo chmod +x /opt/minecraft/start.sh && sudo chown -R minecraft:minecraft /opt/minecraft.

  2. 2

    Run the server once

    sudo -u minecraft /opt/minecraft/start.sh — it creates eula.txt and stops.

  3. 3

    Accept the EULA

    Set eula=true in /opt/minecraft/eula.txt — that confirms you agree to the Minecraft EULA.

  4. 4

    Check the start

    Run start.sh again, wait for Done in the console, then shut the server down with stop.

Step 4. The console in tmux

A server started right in an SSH session stops as soon as you disconnect. tmux keeps the console in the background: you can disconnect and come back to the same console later.

ActionCommand
Open the server consolesudo -u minecraft tmux attach -t mc
Leave without stopping the serverCtrl+B, then D
Send a command without opening the consolesudo -u minecraft tmux send-keys -t mc "say Restart in 5 minutes" Enter
See whether the session is runningsudo -u minecraft tmux ls
The mc session is created by the systemd unit in the next step

Step 5. Autostart with systemd

systemd starts the server when the machine boots and brings it back if the process ends. The unit below creates a tmux session with the server, and on stop it sends stop to the console and waits until the server has saved its worlds and exited. Without that wait, systemd would kill the process before the chunks were written.

/etc/systemd/system/minecraft.service
[Unit]
Description=Minecraft server (Paper)
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
User=minecraft
WorkingDirectory=/opt/minecraft
# the server console lives in the tmux session "mc"
ExecStart=/usr/bin/tmux new-session -d -s mc /opt/minecraft/start.sh
# "stop" saves the worlds; wait until the server is down and the session closes
ExecStop=/bin/sh -c 'tmux send-keys -t mc "stop" Enter; while tmux has-session -t mc 2>/dev/null; do sleep 1; done'
TimeoutStopSec=180
# crashed, or stopped with "stop" in game: start again after 10 seconds
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
enable and check
sudo systemctl daemon-reload
sudo systemctl enable --now minecraft
sudo systemctl status minecraft
sudo systemctl restart minecraft   # restart
sudo systemctl stop minecraft      # clean shutdown through stop

Step 6. The firewall

ufw: SSH and the game port
sudo ufw allow 22/tcp
sudo ufw allow 25565/tcp
sudo ufw enable
sudo ufw status verbose

Allow SSH first, then enable the firewall — otherwise you lock yourself out. Don't open RCON or query to the internet. Ports, checking from outside and SRV records are covered in server IP and port.

Maintenance

  • System updates. sudo apt-get update && sudo apt-get upgrade weekly; a new Linux kernel takes effect after a reboot.
  • Paper updates. Stop the server, replace paper.jar with the new build and start it. Plugins are easiest to update through plugins/update — see Paper.
  • Logs. The current run's log is /opt/minecraft/logs/latest.log; the unit's own events are in journalctl -u minecraft. Reading crashes: logs and crash reports.
  • Backups. The script with save-off, an archive and cron from server backups works with the same mc session.

An anticheat on a VPS

On your own VPS you decide what runs on the server. DGuard is the best anticheat for a modern Minecraft server: it goes into plugins/ next to the latest PacketEvents release, and the key from the panel goes into plugins/DGuard/config.yml. It needs no inbound ports, only outbound HTTPS to DGuard's site — that's where the cloud check with the AI Combat neural network runs. DGuard is free up to 30 players online.

FAQ

How do I keep a Minecraft server running after closing SSH?

Run it in tmux or screen, and for autostart as a systemd service. A server started right in an SSH session stops with it.

Which Java should I install on Ubuntu for a Minecraft server?

Per Paper's docs: Java 25 for 26.1 and newer, Java 21 for 1.20–1.21.11. Paper installs it from the Amazon Corretto repository; headless packages won't do.

Can I run a Minecraft server as root?

Technically yes, but don't: the server and every plugin get rights over the whole machine. Create a dedicated user and run the server as that user.

How do I shut the server down cleanly under systemd?

With sudo systemctl stop minecraft, as long as the unit sends stop to the console and waits for the exit, as in the example above. The server then saves its worlds and disables plugins.

Where do I see server errors on Linux?

In logs/latest.log in the server folder and in journalctl -u minecraft for the service's own events. Minecraft's crash reports are in the crash-reports folder.

Sources

All sections

Run the best anticheat for modern Minecraft

DGuard catches all 47 kinds of cheats in our comparison — the closest rival, Intave, has 27. Full protection on every plan, free up to 30 players online.