# Get started with Endpoint Management

> Make a one-time token, enroll a Linux or macOS device with it, and see the device connected and reporting in your realm.

In this guide you enroll one device, Maya's laptop, into your realm `foobar`, and see it report in. It takes about ten
minutes. At the end the laptop holds its own certificate from your realm, its security sensor is reporting to your
realm's security log, and you can ask it from the realm what it runs.

## Before you begin

- **A realm administrator's session** in `$CVYUH_SESSION`: you need `MODIFY` on the realm's endpoint settings, which
  `RealmOwner` holds ([Who can call](../api/#who-can-call)). [Call the API](../../develop/api/) shows how to get a
  session. Everything here is done through the API.
- **A Linux or macOS machine**, and someone with administrator rights on it to install the package.
- **The package for its platform** (deb or rpm for Linux on amd64 or arm64, pkg for macOS), and **the device
  address** the device connects to (a host and port), both from whoever runs your deployment.
- **Outbound access** from the machine to the device address, with no proxy in between; see
  [Device client](../enrollment/device-client/#network).

The device client is named for your deployment. These steps use `cvyuh-uem`, installed under `/var/cvyuh` on Linux
and `/Library/Cvyuh` on macOS.

## Enroll a device

<Steps>

1. **Make an enrollment token.** Ask the realm for a token that lasts long enough to install, four hours here:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/enrolment-tokens \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{"ttlHours": 4}'
   ```

   The realm answers `201`:

   ```json
   { "token": "<enrollment token>", "expiresAt": "<RFC 3339 time>" }
   ```

   The token enrolls one device into `foobar`. Get it to the laptop by a channel you trust. The address ends in
   `enrolment-tokens`, spelled that way.

2. **Install the package** on the laptop:

   <Tabs syncKey="os">
   <TabItem label="Linux">

   ```sh
   sudo apt install ./<package>.deb
   ```

   On a distribution that uses rpm, `sudo dnf install ./<package>.rpm`.

   </TabItem>
   <TabItem label="macOS">

   ```sh
   sudo installer -pkg ./<package>.pkg -target /
   ```

   </TabItem>
   </Tabs>

3. **Enroll the laptop** with the token, the device address, and your realm's sign-in address,
   `https://foobar.cvyuh.com/oauth2`.

   <Tabs syncKey="os">
   <TabItem label="Linux">

   ```sh
   sudo /var/cvyuh/bin/cvyuh-uem enroll --name maya-laptop \
     --server <device address> --token <enrollment token> \
     --issuer https://foobar.cvyuh.com/oauth2
   ```

   </TabItem>
   <TabItem label="macOS">

   ```sh
   sudo /Library/Cvyuh/bin/cvyuh-uem enroll --name maya-laptop \
     --server <device address> --token <enrollment token> \
     --issuer https://foobar.cvyuh.com/oauth2
   ```

   </TabItem>
   </Tabs>

   It prints the name the device was enrolled as, and the date to enroll it again before:

   ```
   enrolled maya-laptop as <certificate name> against <device address>; enrol again before <RFC 3339 time>
   ```

4. **Start the device client.**

   <Tabs syncKey="os">
   <TabItem label="Linux">

   Start it now, and with every boot:

   ```sh
   sudo systemctl enable --now cvyuh-uem
   ```

   </TabItem>
   <TabItem label="macOS">

   Nothing to do: the installer started it as the `com.cvyuh.endpoint` launch daemon, and it connects as soon as
   the laptop is enrolled.

   </TabItem>
   </Tabs>

5. **See it in the realm.** List the realm's devices:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1 \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

   `maya-laptop` is there, `active` and connected:

   ```json
   [
     {
       "id": "<device id>",
       "uid": "maya-laptop",
       "status": "active",
       "os": "linux",
       "enrolledAt": "<RFC 3339 time>",
       "dar": { "agentId": "<sensor id>" },
       "connected": true
     }
   ]
   ```

   Keep its `id`, the device id. `dar.agentId` is its security sensor's id, which
   [Detection & Response](../../detection-response/) calls take.

6. **Ask it what it runs.** Run the `report` action on the device, over its own connection:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/do \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{"kind": "report"}'
   ```

   The laptop answers with its client's version, its operating system, and whether its security sensor (`dar`) and
   AI tools agent (`aig`) are running:

   ```json
   {
     "id": "<action id>",
     "ok": true,
     "detail": { "version": "<version>", "os": "linux", "dar": { "running": true }, "aig": { "running": true } }
   }
   ```

</Steps>

Within a few minutes the laptop's security sensor also appears in the Detection & Response sensors list, and its
[system inventory](../devices/system-inventory/) in the security log.

<Aside type="caution" title="A token is as good as a device">
  Until it's spent or expires, anyone holding the token can enroll a machine into your realm, and a token can't be
  withdrawn once made. Keep lifetimes short, and keep the realm's [Device limits](../enrollment/device-limits/) close
  to what you need.
</Aside>

If `enroll` was refused, or the device doesn't show as connected, see
[If enrollment fails](../enrollment/device-enrollment/#if-enrollment-fails) and the device client's
[Troubleshooting](../enrollment/device-client/#troubleshooting). The certificate lasts a year: enroll the device again
before the date `enroll` printed ([Enroll a device again](../guides/enroll-a-device-again/)).

If you're done trying it out, remove the device: `DELETE` on `https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>`
(see [Device removal](../revoke-and-remove/removal/)).

## Next steps

<CardGrid>
  <LinkCard title="Get started with AI Governance" description="Have Maya approve the laptop, and see the AI tools on it." href="../../ai-governance/get-started/" />
  <LinkCard title="Get started with Detection & Response" description="See an alert from the laptop and act on it." href="../../detection-response/get-started/" />
  <LinkCard title="Cut off a lost device" description="Revoke a device the moment it's lost, and restore or remove it later." href="../guides/cut-off-a-lost-device/" />
</CardGrid>
