# Device codes and fleet pushes

_For tartan 0.9.36._

A join code lets devices into your organization.

A join code lets devices into your organization. A device code lets in one; a fleet code lets in many, for an RMM push.

Each code sets the zone and tags its devices land with. Only its hash is stored: the code itself is shown once.

## 1. Choose the kind

| | Device code | Fleet code |
|---|---|---|
| Lets in | 1 device | up to `--cap` devices |
| Lives | 24 hours by default, at most 7 days | 7 days by default, at most 30 days |
| Who makes it | an Owner, Admin or Tech | an Owner or Admin |

`--ttl` takes hours or minutes (`168h`, `30m`), never days. A Tech's code carries only the tags Techs may apply.

## 2. Make it

In the console, open **Devices** or **Join codes** and choose **Add a device** (Ctrl D). Pick **One device** or
**Many (fleet)** with a device cap, then **Valid for**, **Zone** and **Tags**, and choose **Create code**. Your
passkey approves it.

With the CLI, your passkey approves it too:

```sh
tartan code create --org acme --kind fleet --cap 40 --ttl 168h --json
```

Add `--zone` and `--groups` for where its devices land. Add `--require_approval` to hold each device until someone
approves it ([Your first device](first-device.md), step 3).

The answer carries `code`, `link` (the join link), `expires_at` and, for an organization in the Tartan registry,
`install_lines`: the one-line installs for Windows and Linux. The lines never carry the code or the link.

## 3. Push it with your RMM

Keep the join link in your RMM as a masked variable named `TARTAN_JOIN`. The installer reads it, clears it before it
starts anything else, and joins with it. A bare code is refused: the link names its own organization. Set `TARTAN_ORG`
to `acme` too, and the installer joins only that organization.

**Windows.** Run the Windows line from `install_lines.windows` as SYSTEM, with `; exit $c` added at its end, so the
job ends with the installer's exit code.

**Linux.** Run the Linux line from `install_lines.linux` as a user that may `sudo`. Its `sudo
--preserve-env=TARTAN_JOIN,TARTAN_ORG` keeps both variables.

The job's last output line is the installer's verdict. Exit `0` is installed; `2` no join link; `3` not elevated;
`12` a download failed; `13` a check refused a file and nothing was installed.

## 4. See and cancel codes

```sh
tartan code list --org acme --json
tartan code revoke --org acme --hash <hash from the list> --dry-run --json
tartan code revoke --org acme --hash <hash from the list> --json
```

In the console, **Join codes** lists them under the code's hash, with **Revoke** on each live one. A revoked code
stops working at once; devices that already joined with it stay.

## Check it worked

```sh
tartan device list --org acme --schema tartan.device.v1 --json
```

Every pushed device shows with the code's `zone` and `groups`. `code list` shows how many joined with each code.

## Next

- [Windows and Linux](windows-linux.md)
- [Remove or revoke a device](remove-device.md)
- [Zones and firewall rules](firewall.md)
