> 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-macos.md).

# Install the agent on macOS

Install the SONAR agent on an Intel or Apple silicon Mac with the command from Agents › Install Agent, check what it installs, and verify the Mac reports in.

## What this is and when to use it

On macOS, **Agents › Install Agent** produces a one-line Terminal command bound to one client and site. Run on the Mac, the command downloads the SONAR agent for the architecture you chose and runs it with `sudo`. The agent then installs the remote access agent, registers the device and creates its launch daemon. The same command works on any number of Macs of that site while it is valid.

## Before you start

* Your role has **Install Agents** in **Admin Center › Roles**, and access to the target site.
* The Mac runs macOS 12 Monterey or later. Check its processor: `uname -m` returns `arm64` on Apple silicon and `x86_64` on Intel. See [Endpoint requirements](https://wiki.datadike.com/sonar/deploy-operate/requirements.md).
* You can run commands with `sudo` on the Mac.
* The Mac 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

### Get the command

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 **macOS**.
4. Under **Agent type**, select **Workstation** or **Server**.
5. Under **Architecture**, select **Apple Silicon** or **Intel 64-bit**.
6. Optionally switch on **Enable token expiration (hours)** and enter the **Hours** the command stays valid.
7. Click **View macOS install instructions**. The **Manual Installation** dialog opens with *Run the following command in your terminal*.
8. Click **Copy Command Line**. To add an argument from **Optional Arguments** — for example `-desc "Design team iMac"` — append it to the end of the command.

**Optional features** apply to Windows devices. The macOS installation does not use them.

### Run it on the Mac

1. Open **Terminal** on the Mac, in a folder you can write to, such as your home folder.
2. Paste the command and press Return. It downloads the agent file `sonaragent-v<version>-darwin-<architecture>`, makes it executable and runs it with `sudo`.
3. Enter the administrator password when `sudo` asks for it.
4. Wait for *Installation was successful!* in the output.

The agent copies itself to `/opt/sonaragent/`, so the downloaded file can be deleted afterwards.

### Folders macOS protects

On a Mac, the remote access window of SONAR offers **Terminal**, **File Browser** and **Processes**. macOS keeps some folders — a user's Desktop, Documents and Downloads among them — out of reach of background services until they are allowed. To browse or change those folders from **Terminal** or **File Browser**, allow the remote access agent, `meshagent` in `/opt/sonarmesh/`, under **Full Disk Access** in **System Settings › Privacy & Security**. On managed Macs, an MDM configuration profile (Privacy Preferences Policy Control) can grant the same permission.

## What you should see

What the installation creates:

| Item                | Where                                                                                                                    |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| SONAR agent         | `/opt/sonaragent/sonaragent`                                                                                             |
| Agent launch daemon | `/Library/LaunchDaemons/sonaragent.plist`, label `sonaragent`. Starts at boot and is restarted automatically if it stops |
| Agent configuration | `/etc/sonaragent.json`                                                                                                   |
| Agent log           | `/var/log/sonaragent.log`                                                                                                |
| Remote access agent | `/opt/sonarmesh/`, launch daemon label `meshagent`                                                                       |

If the Mac already had an agent, the installer removes the old agent and the old remote access agent first (*Existing meshagent found, attempting to remove...*, *Existing sonaragent plist found, attempting to remove...*) and then installs again.

## How to verify it worked

1. On the Mac:

   ```bash
   sudo launchctl print system/sonaragent | grep state
   sudo launchctl print system/meshagent | grep state
   ```

   Both must show `state = 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 Mac, 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, once the remote access agent has connected, **Remote Online**.
4. Click **Take Control**. The remote access window opens on **Terminal**, with a shell on the Mac.
5. In **Reports & Audits › Audits**, an **Agent Install** entry records the new agent with its host name.

## Common errors

| Symptom                                                                                                     | Cause                                                                       | Fix                                                                                                                        |
| ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| *must run as root*                                                                                          | The agent was run without `sudo`                                            | Run the whole command again as copied; it already includes `sudo`                                                          |
| The shell reports *Bad CPU type in executable*                                                              | The architecture chosen does not match the Mac                              | Get the command again with the other **Architecture**                                                                      |
| *Installer token has expired. Please generate a new one.*                                                   | The command was generated with token expiration and the time has passed     | Get a new command                                                                                                          |
| *Old installer detected (version …). Latest version is … Please generate a new installer from the RMM*      | The command was saved before the SONAR agent version changed                | Get a new command                                                                                                          |
| *Unable to download the mesh agent from the RMM.*                                                           | The installer could not get the remote access agent through the API address | Check connectivity to the API address and run the command again                                                            |
| **Terminal** or **File Browser** gets *Operation not permitted* in a user's Desktop, Documents or Downloads | macOS protects those folders                                                | Allow `meshagent` under **Full Disk Access**                                                                               |
| The device is online but shows **Remote Offline**                                                           | The remote access agent cannot reach the remote access address              | See [Troubleshoot agents](https://wiki.datadike.com/sonar/deploy-operate/troubleshooting.md#a-device-shows-remote-offline) |

## Field reference

| Field                               | What it does                                                               | Accepted values                     | Default                        |
| ----------------------------------- | -------------------------------------------------------------------------- | ----------------------------------- | ------------------------------ |
| **Client**                          | Client the Mac is registered under                                         | Clients your role can access        | First client in the list       |
| **Site**                            | Site the Mac 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 Mac as a workstation or a server, shown in the **Type** column | **Workstation**, **Server**         | **Workstation**                |
| **Architecture**                    | Processor architecture of the agent the command downloads                  | **Intel 64-bit**, **Apple Silicon** | **Intel 64-bit**               |
| **Enable token expiration (hours)** | When on, the command stops working after the number of hours entered       | On, off; **Hours** from 1 to 999999 | Off; 24 hours when switched on |

### Optional arguments

| Argument                           | What it does                                                                                                                               |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `-log debug`                       | Verbose output during the install                                                                                                          |
| `-silent`                          | Accepted for compatibility with the Windows installer. It changes nothing on macOS: the install always writes its messages to the terminal |
| `-nomesh`                          | Does not install the remote access agent. The remote access window is then unavailable for the Mac                                         |
| `-desc "<text>"`                   | Sets the device **Description**                                                                                                            |
| `-proxy "http://proxyserver:port"` | Uses an HTTP proxy. See [Network requirements](https://wiki.datadike.com/sonar/deploy-operate/network-requirements.md#proxies)             |

## 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)
* [Remote terminal](https://wiki.datadike.com/sonar/administration/remote-access/remote-terminal.md)
* [Remove agents](https://wiki.datadike.com/sonar/deploy-operate/remove-agents.md)
* [Troubleshoot agents](https://wiki.datadike.com/sonar/deploy-operate/troubleshooting.md)
