> For the complete documentation index, see [llms.txt](https://wiki.datadike.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.datadike.com/sonar/deploy-operate/install-agent-linux.md).

# Install the agent on Linux

Download the Linux install script from Agents › Install Agent, run it as root, and confirm the sonaragent systemd service and the device in Sysadmin.

## What this is and when to use it

On Linux, **Agents › Install Agent** produces a shell script bound to one client and site. Run as root on the device, the script downloads the SONAR agent, installs the remote access agent, registers the device and creates the `sonaragent` systemd service. The same script can be reused on any number of Linux devices of that site while it is valid, and it is also the uninstaller.

## Before you start

* Your role has **Install Agents** in **Admin Center › Roles**, and access to the target site.
* The device runs a Linux distribution with systemd as its init system: `ps --no-headers -o comm 1` must print `systemd`. See [Endpoint requirements](https://wiki.datadike.com/sonar/deploy-operate/requirements.md).
* You can run commands as `root` on the device, from SSH or a text console. The script refuses to run from a graphical session.
* `bash` and `wget` are installed.
* The device can reach the SONAR API address and the remote access address on 443/tcp. See [Network requirements](https://wiki.datadike.com/sonar/deploy-operate/network-requirements.md).

## Steps

1. Open **Agents › Install Agent**, or click **New Agent** on the **Dashboard › Sysadmin** device list.
2. Choose the **Client** and the **Site**.
3. Under **Operating system**, select **Linux**.
4. Under **Agent type**, select **Workstation** or **Server**.
5. Under **Architecture**, select **64-bit**, **32-bit**, **ARM 64-bit** or **ARM 32-bit**, matching the device (`uname -m`: `x86_64`, `i686`, `aarch64`, `armv7l`).
6. Optionally switch on **Enable token expiration (hours)** and enter the **Hours** the script stays valid.
7. Click **Download Linux install script (.sh)**. The file is named `sonar-<client>-<site>-<type>.sh`.
8. Copy the script to the device, for example with `scp`.
9. On the device, run it as root:

   ```bash
   sudo bash ./sonar-<client>-<site>-<type>.sh
   ```

   To see verbose output while the agent registers, add `--debug`. To install the SONAR agent without the remote access agent, add `--nomesh`; remote control is then unavailable on that device.

**Optional features** apply to Windows devices. The Linux script does not use them.

## What you should see

The script prints its progress:

```
Downloading sonar agent...
Downloading and installing mesh agent...
Getting mesh node id...
```

followed by the agent's own registration output, ending with *Installation was successful!*

What the script installs:

| Item                | Where                                                                                                                                                                               |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| SONAR agent         | `/usr/local/bin/sonaragent`                                                                                                                                                         |
| Agent service       | `sonaragent.service`, unit file `/etc/systemd/system/sonaragent.service`, description *Sonar RMM Linux Agent*. Runs as `root`, enabled at boot, restarted automatically if it stops |
| Agent configuration | `/etc/sonaragent.json`                                                                                                                                                              |
| Agent log           | `/var/log/sonaragent.log`                                                                                                                                                           |
| Remote access agent | `/opt/sonarmesh/`, service `meshagent.service`                                                                                                                                      |

Before it installs, the script removes any previous SONAR agent and remote access agent it finds on the device, so running it again reinstalls cleanly. Before installing the remote access agent it also generates the `en_US.UTF-8` locale and sets it as the system locale.

## How to verify it worked

1. On the device:

   ```bash
   systemctl status sonaragent
   systemctl status meshagent
   ```

   Both must report `active (running)`.
2. In the console, open **Dashboard › Sysadmin**, pick the client and search for the host name. The row shows **Agent Status** **Online**, the **OS** reported by the device, the **Client**, **Site** and **Type** you chose, and today's date in **First Seen**.
3. Select the row. The details panel header shows the agent version, and no **Remote Offline** pill once the remote access agent has connected.
4. In **Reports & Audits › Audits**, an **Agent Install** entry records the new agent with its host name.

## Common errors

| Symptom                                                                                                | Cause                                                                                                                                                         | Fix                                                                                                                     |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| *ERROR: Must be run as root*                                                                           | The script was not run as root                                                                                                                                | Run it with `sudo` or as `root`                                                                                         |
| *This install script only supports systemd*                                                            | The distribution does not use systemd                                                                                                                         | The agent needs systemd; see [Endpoint requirements](https://wiki.datadike.com/sonar/deploy-operate/requirements.md)    |
| *ERROR: Display detected. Installer only supports running headless, i.e from ssh.*                     | The script was started from a graphical session, or with X forwarding                                                                                         | Run it over SSH, switch to a text session with `sudo systemctl isolate multi-user.target`, or run `unset DISPLAY` first |
| *ERROR: Unknown parameter: …*                                                                          | An argument the script does not accept was passed. With `uninstall` as the only argument the script uninstalls; otherwise it accepts `--debug` and `--nomesh` | Remove the argument                                                                                                     |
| *ERROR: Unable to download sonar agent*                                                                | The device cannot download from the API address                                                                                                               | Check 443/tcp and name resolution for the API address                                                                   |
| *Installer token has expired. Please generate a new one.*                                              | The script was generated with token expiration and the time has passed                                                                                        | Download a new script                                                                                                   |
| *Old installer detected (version …). Latest version is … Please generate a new installer from the RMM* | The script was saved before the SONAR agent version changed                                                                                                   | Download a new script                                                                                                   |
| The script stays at *Getting mesh node id...*                                                          | The remote access agent did not start or cannot reach the remote access address                                                                               | Check `systemctl status meshagent` and connectivity to the remote access address on 443/tcp                             |
| `sonaragent` is running but the device never shows **Online**                                          | The agent cannot keep its connection to the API address                                                                                                       | See [Troubleshoot agents](https://wiki.datadike.com/sonar/deploy-operate/troubleshooting.md)                            |

## Field reference

| Field                               | What it does                                                                  | Accepted values                                        | Default                        |
| ----------------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------ | ------------------------------ |
| **Client**                          | Client the device is registered under                                         | Clients your role can access                           | First client in the list       |
| **Site**                            | Site the device is registered under                                           | Sites of the chosen client                             | First site of the client       |
| **Operating system**                | Platform of the installer                                                     | **Windows**, **Linux**, **macOS**                      | **Windows**                    |
| **Agent type**                      | Records the device as a workstation or a server, shown in the **Type** column | **Workstation**, **Server**                            | **Workstation**                |
| **Architecture**                    | Processor architecture of the agent the script downloads                      | **64-bit**, **32-bit**, **ARM 64-bit**, **ARM 32-bit** | **64-bit**                     |
| **Enable token expiration (hours)** | When on, the script stops working after the number of hours entered           | On, off; **Hours** from 1 to 999999                    | Off; 24 hours when switched on |

### Script arguments

| Argument    | What it does                                                                                                                                                    |
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--debug`   | Prints verbose output while the agent registers                                                                                                                 |
| `--nomesh`  | Does not install the remote access agent                                                                                                                        |
| `uninstall` | Removes the SONAR agent and the remote access agent instead of installing. See [Remove agents](https://wiki.datadike.com/sonar/deploy-operate/remove-agents.md) |

## Related pages

* [Endpoint requirements](https://wiki.datadike.com/sonar/deploy-operate/requirements.md)
* [Network requirements](https://wiki.datadike.com/sonar/deploy-operate/network-requirements.md)
* [Deploy agents at scale](https://wiki.datadike.com/sonar/deploy-operate/mass-deployment.md)
* [Remove agents](https://wiki.datadike.com/sonar/deploy-operate/remove-agents.md)
* [Troubleshoot agents](https://wiki.datadike.com/sonar/deploy-operate/troubleshooting.md)
