# Install the agent

> Put the Clokeep agent on a Linux server with one command and see it come online.

The Clokeep agent runs on each server you back up. The panel generates the install command for each server, with its own token.

## Prerequisites

- A Linux server on x86_64 (amd64) or arm64, with systemd and `curl`.
- Root access on the server. The command runs with `sudo`.
- Outbound HTTPS from the server to `app.clokeep.com`.
- Outbound access from the server to your storage. The agent uploads backups straight to it.
- For database plans, `mysqldump` or `pg_dump` on the server.
- Free disk space where the agent stages backups. See [Disk space and the work folder](#disk-space-and-the-work-folder).

The panel never connects to your server. The agent opens every connection, so you open no inbound ports.

## Install

<Steps>
<Step title="Add the server">
In the panel, open **Servers** and click **New server**. Enter a name, such as `web-01`, and click **Create**.

The server's page opens. Under **Agent status** it shows **Pending**, because the agent has not checked in yet.
</Step>
<Step title="Generate the install command">
On the server's page, find **Install agent on this server** and click **Generate install command**.

The command appears under **Run on remote server**. Its token is valid for one use, and for 24 hours by default. The panel shows how long it stays valid.

<Frame caption="The install section on a new server's page, before you generate the command.">
![The Install agent on this server section with the Generate install command button](/images/docs/install-agent-generate-command.png)
</Frame>
</Step>
<Step title="Run the command on the server">
Click the clipboard button to copy the command. Open an SSH session on the server and paste it.

The command looks like this. Copy yours from the panel, because it carries your own token.

```bash Install
curl -fsSL https://app.clokeep.com/agent/install.sh | sudo bash -s -- --url 'https://app.clokeep.com' --token 'YOUR_ENROLLMENT_TOKEN'
```

The command downloads the agent, enrolls it with the panel and starts it as a systemd service. When it finishes, the output reads:

```text Output
==> Agent installed and started
```
</Step>
<Step title="Check that the server is Online">
Reload the server's page in the panel. **Agent status** shows **Online**, with the time the agent was last seen.

The agent also reports the server's IP address, operating system, control panel and agent version. They appear on the same page.
</Step>
</Steps>

<Note>
An install command works once: after it enrolls, the agent signs in with its own key. Generating a new install command or enrollment token for the server retires any earlier one that was not used.
</Note>

## What the command installs

- The agent program at `/usr/local/bin/clokeep-agent`.
- Its settings at `/etc/clokeep-agent.yaml`. This file holds the agent's key.
- Its default work folder at `/var/lib/clokeep-agent`. See [Disk space and the work folder](#disk-space-and-the-work-folder).
- A systemd service named `clokeep-agent`, which starts at boot and restarts if it stops.

The agent updates itself after that. To check its version, restart, reinstall or remove it, see [Agent updates](/docs/servers/agent-updates).

On a server without [Plesk](/docs/servers/plesk) or [cPanel](/docs/servers/cpanel), the agent restores files into `/var/lib/clokeep-restore`, and into other folders only once you allow them in its settings. See [Restore files, email and databases](/docs/restores/files-databases#allowed-folders).

## Disk space and the work folder

The agent stages each backup in its work folder, then uploads it:

- A full **Files** or **Email** backup needs room for a full copy of the data plus the archive. An incremental backup copies only the files that changed.
- A **Database** backup needs room for the dump plus its archive.
- An encrypted backup also needs room for a second copy of the archive while it uploads.
- A **Plesk server** or **cPanel server** backup works one hosting account at a time, so it needs that room for the largest account.
- A restore needs room for the backup and the earlier backups of its chain, each both downloaded and unpacked, at the same time.

To use another disk, an Admin or Operator picks it under **Work directory** on the server's page and clicks **Save changes**. The list shows the disks the agent found, with their free space. **Auto** picks the disk with the most free space at each run. Left empty, the agent uses its default folder. On another disk, the agent works in a `.clokeep-agent` folder at the disk's root. That folder stays when you choose another place.

## Server status

A server's status comes from the agent's last check-in:

- **Online** means the agent checked in within the last few minutes.
- **Offline** means the agent checked in before but has gone quiet.
- **Pending** means the agent has never checked in.

Backups run only while the agent checks in.

## Troubleshooting

<Accordion title="The command stops after Checking panel connectivity">
The server fetched the install script, but it could not download the agent from the panel.

The installer downloads the agent, and later enrolls it, at the address after `--url`. Check that it reads `'https://app.clokeep.com'`, exactly as the panel shows it. Copy the command from the panel again if you edited it.

If the address is right, the server cannot reach the panel at that address.
</Accordion>

<Accordion title="enrollment failed: connection refused">
The agent could not reach the panel when it tried to enroll. Check the address after `--url` as for the previous error. If it is right, the panel cannot be reached from the server.
</Accordion>

<Accordion title="enrollment failed: api error 401">
The full message reads `enrollment failed: api error 401: Invalid or expired enrollment token.` The token in the command has expired or was used already. On the server's page, click **Regenerate** next to the command, or **Generate install command**, and run the new command.
</Accordion>

<Accordion title="Unsupported architecture">
The agent runs on x86_64 (amd64) and arm64 servers only.
</Accordion>

<Accordion title="clokeep-agent did not start">
The agent was installed but its service did not stay up. Read its log on the server:

```bash Read the log
journalctl -u clokeep-agent
```
</Accordion>

<Accordion title="load config failed">
The agent cannot read `/etc/clokeep-agent.yaml`, usually because it never enrolled. Generate a new install command in the panel and run it on the server.
</Accordion>

<Accordion title="The server stays Pending or turns Offline">
The agent is not checking in. Check that its service is running:

```bash Check the service
sudo systemctl status clokeep-agent
```

If it is stopped, start it again:

```bash Restart the service
sudo systemctl restart clokeep-agent
```

If it runs but the server stays **Offline**, check that the server can reach the panel:

```bash Check the panel connection
curl -s -o /dev/null -w '%{http_code}\n' https://app.clokeep.com/agent/install.sh
```

The command prints `200` when the server reaches the panel. It prints `000` when the server cannot reach the panel. Any other code means the server reached something that did not answer as the panel does, so check the address.
</Accordion>

<Accordion title="Backups stay Queued">
A run waits as **Queued** until the server's agent picks it up. Check that the server shows **Online**. If it does not, follow the steps for a server that stays Pending or Offline.
</Accordion>

## Next steps

<CardGroup cols="2">
<Card title="Quickstart" href="/docs/quickstart" icon="play">
Add a storage and a plan, then run your first backup.
</Card>
<Card title="S3 storage" href="/docs/storage/s3" icon="layers">
Add the storage your backups go to. SFTP and FTP have their own pages.
</Card>
</CardGroup>
