# Install and Configure xmrig for Monero XMR Crypto Mining

<p class="callout warning">Ensure you have created and activated an account on [https://minergate.com. ](https://minergate.com)You will need your minergate.com UserID before proceeding.</p>

### Install and Configure xmrig

Create a directory for xmrig under /opt:

```
mkdir /opt/xmrig
```

Download attached [xmrig-linux.zip](https://docs.deeztek.com/attachments/7) and extract to the **/opt/xmrig** directory you created above:

```
unzip xmrig-linux.zip -d /opt/xmrig
```

Edit /opt/xmrig/config.json file and under the following section:

<div id="bkmrk-%22pools%22%3A-%5B-%7B-%22algo%22%3A">```
"pools": [<br></br>        {<br></br>            "algo": null,<br></br>            "coin": null,<br></br>            "url": "xmr.pool.minergate.com:45700",<br></br>            "user": "12345678",<br></br>            "pass": "x",<br></br>            "rig-id": null,<br></br>            "nicehash": false,<br></br>            "keepalive": false,<br></br>            "enabled": true,<br></br>            "tls": false,<br></br>            "tls-fingerprint": null,<br></br>            "daemon": false,<br></br>            "socks5": null,<br></br>            "self-select": null<br></br>        }<br></br>    ],
```

</div>set the **123456** in the **"user": "12345678"** section to your Minergate.com UserID.

Make /opt/xmrig/xmrig executable:

```
chmod +x /opt/xmrig/xmrig
```

Move the **xmrig.service** file that was included in the xmrig-linux.zip file to /etc/systemd/system:

```
mv /opt/xmrig/xmrig.service /etc/systemd/system/
```

### Configure CPU Quota

Adjust the CPU Quota that xmrig will use on your system by editing the **/etc/systemd/system/xmrig.service** file:

```
vi /etc/systemd/system/xmrig.service
```

Insert the following line:

```
CPUQuota=50%
```

after the following line:

```
ExecStart=/opt/xmrig/xmrig --config=/opt/xmrig/config.json --log-file=/opt/xmrig/xmrig.log
```

So the whole service looks like below:

```
[Unit]
Description=XMRig Monero Miner
After=network.target

[Service]
User=xmrig
Group=xmrig

StandardOutput=journal
StandardError=journal

ExecStart=/opt/xmrig/xmrig --config=/opt/xmrig/config.json --log-file=/opt/xmrig/xmrig.log
CPUQuota=50%

Restart=always

[Install]
WantedBy=multi-user.target
```

Adjust the percentage from the default **50%** to a level appropriate for your system.

Save the **/etc/systemd/system/xmrig.service** file.

### Create User for xmrig

Create a user for xmrig:

```
sudo adduser xmrig
```

Set a password for the xmrig user and answer the resultant prompts

Give xmrig user root privileges:

```
usermod -G sudo xmrig
```

### Configure Logging

Create **/opt/xmrig/xmrig.log** file:

```
touch /opt/xmrig/xmrig.log
```

Set **/opt/xmrig/xmrig.log** file permissions:

```
chmod 664 /opt/xmrig/xmrig.log
```

Set **/opt/xmrig/xmrig.log** file owner to the xmrig user created earlier:

```
chown xmrig:xmrig /opt/xmrig/xmrig.log
```

### Enable and Start xmrig Service

Enable the xmrig service:

```
sudo systemctl enable --now xmrig
```

Start the xmrig service:

```
sudo systemctl restart xmrig
```

Ensure xmrig service has started:

```
systemctl status xmrig
```

If the service is started, the output should be similar to below:

```
● xmrig.service - XMRig Monero Miner
   Loaded: loaded (/etc/systemd/system/xmrig.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2021-02-19 21:17:30 UTC; 11min ago
 Main PID: 7516 (xmrig)
    Tasks: 14 (limit: 4915)
   CGroup: /system.slice/xmrig.service
           └─7516 /opt/xmrig/xmrig --config=/opt/xmrig/config.json --log-file=/opt/xmrig/xmrig.log

```

View xmrig service logs:

```
journalctl -u xmrig
```

View xmrig logs:

```
tail -f /opt/xmrig/xmrig.log
```