Home

How do I run XMRig as a systemd service on Linux?

You can run XMRig as a systemd service so Linux starts it at boot and restarts it if it crashes. The safest setup uses a dedicated account with limited permissions, an explicit configuration file, and systemd’s built-in logs.

1. Put XMRig in a permanent location

These steps assume your Linux distribution uses systemd, the service manager used by distributions such as Ubuntu, Debian, and Fedora. You also need a working XMRig binary—the executable mining program—from the official project or a build you trust.

Only mine on hardware you own or have explicit permission to use. Avoid “preconfigured” downloads from strangers; they may contain malware or someone else’s wallet address.

From the folder containing your working xmrig executable, run:

sudo useradd --system --no-create-home \
  --shell /usr/sbin/nologin xmrig

sudo install -d -m 755 /opt/xmrig /etc/xmrig
sudo install -m 755 ./xmrig /opt/xmrig/xmrig

The xmrig account cannot log in normally. If it already exists, skip the account-creation command.

2. Create your mining configuration

A mining pool combines work from many miners and distributes rewards. Get its server address, port, and connection instructions before continuing.

Create the configuration:

sudo nano /etc/xmrig/config.json

Paste this starting point:

{
  "autosave": false,
  "background": false,
  "cpu": {
    "enabled": true,
    "max-threads-hint": 50
  },
  "randomx": {
    "rdmsr": false,
    "wrmsr": false
  },
  "pools": [
    {
      "coin": "monero",
      "url": "POOL_HOST:PORT",
      "user": "YOUR_XMR_WALLET_ADDRESS",
      "pass": "x",
      "tls": true
    }
  ]
}

Replace the placeholders. Use a pool port that supports TLS, which encrypts the connection, or adjust tls to match the pool’s instructions. Some pools require a different pass value.

Your wallet address receives payments; never put your wallet’s seed phrase or private keys here.

The thread hint starts with fewer CPU threads, but it is not a strict 50% CPU limit. The MSR options disable privileged processor tuning; performance may be lower, but you avoid running the miner as root.

Protect the file while allowing the service to read it:

sudo chown root:xmrig /etc/xmrig/config.json
sudo chmod 640 /etc/xmrig/config.json

3. Add the systemd service

Create the service definition:

sudo nano /etc/systemd/system/xmrig.service

Paste:

[Unit]
Description=XMRig Monero miner
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=xmrig
Group=xmrig
WorkingDirectory=/opt/xmrig
ExecStart=/opt/xmrig/xmrig --config=/etc/xmrig/config.json
Restart=on-failure
RestartSec=10
Nice=10
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Keep "background": false: systemd needs XMRig to stay in the foreground to track it correctly.

Nice=10 gives other programs scheduling preference. The protection settings restrict file access without granting administrator privileges.

4. Start it and check the logs

Load the definition and enable startup at boot:

sudo systemctl daemon-reload
sudo systemctl enable --now xmrig
systemctl status xmrig
sudo journalctl -u xmrig -f

Press Ctrl+C to stop watching logs; mining continues. Look for a successful pool connection and accepted shares—pieces of work submitted to the pool.

After changing the mining configuration:

sudo systemctl restart xmrig

To stop mining and disable automatic startup:

sudo systemctl disable --now xmrig

If startup fails, check the executable path, file permissions, and JSON punctuation. Huge-page warnings concern a memory optimization; they do not necessarily mean mining has failed.

The bottom line

Run XMRig under its own account, let systemd supervise it, and verify accepted shares in the logs. Monitor temperatures, responsiveness, and electricity use before leaving it running unattended.

All 1,000 questions

MyAiMiner.com

MyAiMiner.com — Monero mining blog. 1,000 questions. Clear answers.

Monero (XMR) Mining BLOG

Hashes0
Blocks accepted0
Blocks rejected0
Runtime00:00:00