Removing and cleaning up Wazuh agents

A practical guide to keeping the Wazuh agent list accurate: removing decommissioned and duplicate agents, finding long-disconnected hosts and preventing key conflicts on rebuilt systems.

On this page

Why removing Wazuh agents cleanly matters at scale

Removing decommissioned, rebuilt and duplicate agents from the Wazuh server is what keeps the agent list an accurate picture of your fleet. Every entry the server still holds is a host it expects to hear from, and stale entries distort fleet visibility: dashboards show hosts as disconnected that no longer exist, counts of active endpoints drift from reality, and reports that depend on the inventory can attribute software to machines that were retired long ago. Vulnerability reporting is affected in the same way, because Wazuh vulnerability detection correlates the software inventory that agents collect with vulnerability data. A ghost agent can keep old findings open or make an exposure look present on a host that has been rebuilt with different software. A removal and cleanup routine answers the question of what the server should still be monitoring, and it should run whenever hosts are retired, when a rebuild reuses a hostname, after a migration that re-enrolls endpoints, and on a regular schedule so long-disconnected entries do not accumulate.

Agent removal is a server-side task. The agent list is managed on the Wazuh server, so the removal is performed there with the server's command-line tools or its API, not on the endpoint. Removing an entry does not uninstall software from the host, so the cleanup has to cover both sides: the endpoint should be decommissioned or reconfigured, and the server record should be removed so the same identity does not linger. Before you start, confirm which agent identities map to which physical or virtual hosts in your environment, and decide whether removal is permanent or whether a host will re-enroll under a new key. Check the exact commands and API fields against the documentation for your installed release, since they can differ between the 4.14 patch releases your environment runs.

Plan the routine as an operational control with an owner, a trigger and a record. Name who may approve removals, define what evidence justifies removing an entry (for example, a decommission ticket or a confirmed rebuild), and keep a log of what was removed and why so auditors and incident responders can explain gaps in the inventory later. Ask whether your change process already covers retirement of endpoints, and decide how removals are reflected in vulnerability and compliance reporting. Treat the first cleanup of a long-running deployment as a planned change, because removing the wrong identity can disconnect a live host from monitoring until it is re-registered.

CLI or API: choosing how to remove agents

The manage_agents tool runs directly on the Wazuh server and lets an administrator list agents, inspect them and remove them interactively or by ID. It fits one-off cleanups, incident work where someone is already logged into the manager, and small fleets where a person reviews each removal before it happens. Because it needs shell access to the server, access to the tool is effectively access to the agent inventory, so it should be limited to a small number of administrators.

  • Best for ad hoc work: a single decommissioned host or a short list reviewed by hand.
  • Shell access required: the operator must be on the server, which suits teams that already manage it through SSH with recorded sessions.
  • Audit trail depends on your logging: confirm whether shell commands are recorded by your bastion, auditd or a session recorder, because the tool itself may not give you a complete record of who removed what.
  • Harder to repeat: typed commands drift between operators unless you keep a runbook with the exact steps.
  • Interactive confirmation helps: prompts reduce accidental deletes during manual work.

Before relying on this path, confirm the command options and prompts in the documentation for your installed version.

Finding long-disconnected and duplicate agents

Before removing anything, you need a list of agents that are probably dead and a way to confirm it. The four approaches below work in parallel: the status view shows what the server last heard, filters narrow the list by age, name and address matching finds rebuilt hosts, and the asset system tells you whether the machine still exists.

Review last keep-alive in the dashboard or API

Each agent reports keep-alive messages to the Wazuh server, and the server records the last time it heard from each one. Open the agents list in the dashboard or query the agents endpoint of the server API to see the status and last keep-alive for every agent. Sort by the oldest keep-alive first so the longest-silent agents appear at the top. Treat this as the starting list, not the verdict, because a silent agent may simply be switched off.

Wazuh docs

Filter disconnected agents by period

Choose a silence window that matches how your organization handles machines that go offline, such as laptops on leave or servers in maintenance. Filter the agents list for the disconnected status and for agents whose last keep-alive is older than that window. Record the window you chose and the date of the filter, so the list can be reproduced during an audit. Confirm the exact filter syntax and status values against your server version, since the interface and API parameters can change between releases.

Match duplicate names and IP addresses

A rebuilt host often enrolls again under the same name or address while the old record stays behind as disconnected. List agents that share a host name or IP address and compare their registration dates and last keep-alive times. The newer, active record is usually the rebuilt host, and the older one is the candidate for removal. Check that two different machines did not legitimately share a name, for example in a cloned or containerized environment, before deleting either record.

Reconcile with the CMDB or asset system

Export the agent inventory and compare it with your configuration management database or asset register. An agent with no matching asset, or an asset marked retired, is a strong removal candidate. An agent whose asset is still active but silent needs investigation rather than deletion. Ask the asset owner to confirm decommissioning, and record that confirmation with the removal ticket. This check catches machines that were retired in the asset system but still appear online to the server.

Weigh the cost of removing too early

Deleting an agent that is only powered off or temporarily unreachable is easy to reverse on the endpoint but not in the record. The host may then re-enroll with a new key, which means its alert history and group assignments no longer line up with the old identity. Keep a removal log, prefer waiting out a known maintenance period, and confirm with the owner before deleting. A host that is only powered off should stay in the inventory until its owner confirms it is retired.

How a cleanup run moves from detection to verification

The run starts with a list of candidate agents pulled from the Wazuh server, where each entry is checked against its last connection time and the asset record. Before anything is deleted, the asset owner confirms whether the host is decommissioned, duplicated or only offline, because a host that is temporarily disconnected should be kept. Approved removals go through the Wazuh server CLI or API, and the run ends by checking that the agent list no longer shows the entry and that the endpoint itself no longer reports. Each hand-off should leave a record of who approved the removal.

Decision path from candidate detection to verified removal.

Avoiding key conflicts when hosts are rebuilt

This sequence retires the old agent record before the rebuilt host enrolls, so each host keeps one unique identity and the agent list shows only live endpoints.

  1. Inventory the host and its existing agent record

    Before rebuilding, record the agent ID, agent name, IP address and group assignment of the existing agent in the Wazuh dashboard or through the API. Confirm which agent record belongs to the host being rebuilt, especially if the hostname will stay the same. Check that the record is the one you expect by comparing the name and last keep-alive time with the host you are about to change. Done means you have a written record of the old agent ID tied to that host, so you can find it later.

  2. Remove or retire the old agent record

    Delete the old agent record from the Wazuh server before the rebuilt host enrolls, using the CLI or API method described in this topic. The agent administrator or the team that owns the server performs this step, and it should happen while the old host is still reachable or immediately after it is powered off. Check the result by listing agents and confirming the old ID is gone or marked for removal. Only then move on, so the new enrollment does not collide with a stale identity.

  3. Keep the agent key out of the golden image

    If the rebuilt host comes from a template or golden image, make sure the image does not contain an installed Wazuh agent with its client key. Remove the agent and its key material during image preparation, or build the image without the agent and install it at first boot. Check the image by confirming no client key file exists in the agent directory and that no agent process is registered. A cloned key means every host built from that image reports under the same identity, so this check is the one that prevents the conflict.

  4. Enroll the rebuilt host with a fresh identity

    Install the agent on the rebuilt host and let it register with the manager using the enrollment method appropriate for your platform. Registration details, including deployment variables, enrollment passwords and the API route for restricted networks, belong in the enrollment topics for each operating system and method. Confirm the host receives a new agent ID that differs from the retired one. Done means the new registration completes without an error about a duplicate or existing agent.

  5. Confirm the new agent reports with a unique identity

    Check that the new agent appears as active with its own ID, IP address and group assignment, and that it sends keep-alive messages to the manager. Review the agent's logs on the endpoint for connection errors, and confirm that alerts from the host carry the new agent name. Ask the team that operates the server to verify that no two active agents share a name or key. Done means the host reports under one current record and nothing else reports under its identity.

  6. Verify the old record no longer shows as active

    Search the agent list for the old agent ID and name to confirm it is removed or shows as disconnected with no recent keep-alive activity. If the old record still appears as active, find out which machine is using its key before taking further action, because a live duplicate means two hosts are sharing an identity. Document the old ID as retired in your asset records. Done means the agent list shows one active record for the rebuilt host and no active record for the old one.

Security and operational risks of careless removal

Removing a Wazuh agent looks like housekeeping, but it changes what your team can see, what can still connect, and what evidence survives. The cards below cover five risks that tend to appear together when removal is done ad hoc, with a practical control for each.

Monitoring gaps on live hosts

Deleting an agent record for a host that is still running removes its alerts and inventory without any signal to the team. Before removal, confirm the host is actually decommissioned in your asset source, check whether the agent is still reporting, and confirm that another control covers the system if it must stay in service. Keep a short written sign-off that names the owner who approved the change.

Vulnerability detection docs

Removals without an audit trail

A removal that happens only through a command on one administrator's shell leaves no record of who deleted which agent or why. Require a change ticket for every removal, record the agent ID, hostname, operating system and removal date, and log the API or CLI session through your central logging. Without this, a later question about a missing host has no answer.

Lingering agent keys and credentials

Removing an agent from the manager list does not automatically invalidate every copy of its key material, and a removed host's keys can remain on disk, in backups or in images. Confirm that the agent's key is no longer accepted, remove copies from the host and any golden image, and rotate the enrollment password if it may have been shared. Treat stale keys as credentials that need the same review as any other.

Deleting evidence compliance depends on

Alerts, inventory and configuration history from a decommissioned host may be the only proof that a control operated during an audit period. Before deleting agent data, check which retention and archival rules apply, export the records your framework requires, and store them in a location your compliance team controls. Ask your compliance lead which evidence must outlive the agent.

Automation that re-enrolls removed hosts

Provisioning scripts, golden images and configuration management can re-register a host that was deliberately removed, bringing back an agent nobody intended to keep. Check deployment variables and image templates for enrollment steps, and gate re-enrollment behind the same approval used for removal. Review enrollment logs after each rebuild to confirm that only expected hosts are registering.

Questions teams ask about agent cleanup

What drives the cost of a Wazuh agent cleanup project?

The cost depends mainly on how many agents are stale, how many environments they sit in, and how much verification the team needs afterward. Self-hosted Wazuh carries no license fee, so the spend is labor: someone must inventory agents, decide what to remove, run removals through the API or manage_agents, and confirm the dashboard and any dependent integrations behave correctly. Costs rise with agents spread across many clusters, with weak naming or labeling, with no owner for each host, and with change approval steps. Ask any partner for a quote built from a written scope listing the environments, agent counts, removal method and the verification steps they expect.

How long does a cleanup project usually take?

No duration figure is supplied for this work, so treat any number you hear as a question to ask. Duration depends on the count of stale and duplicate agents, whether owners confirm each host, how many Wazuh deployments exist, and whether removals must follow a change window. A small, well-labeled fleet with clear ownership moves quickly, while a large fleet with unknown owners spends most of its time on investigation rather than deletion. Ask for a timeline tied to phases: inventory, owner confirmation, removal batches and post-removal checks.

What does the work need from our internal staff?

Internal staff need to supply the knowledge that the Wazuh server cannot provide. That means infrastructure or platform owners who can confirm whether a host is decommissioned, rebuilt or still in service; an administrator with API access to the Wazuh server; and a change approver for production removals. Security staff should also confirm which agents feed compliance evidence or alert pipelines, since removing those agents can break reporting. Plan for these people to answer questions in batches, because owner confirmation is usually the slowest step.

Can our team clean up stale agents without outside help?

Yes, a team with Wazuh administration skills can do this alone, provided it has access to the Wazuh server API, a documented list of hosts and owners, and a safe way to test removals first. The main risks are deleting an agent that is still in use, removing a host whose key is needed for a rebuild, and missing duplicates created by reinstallation. Teams without recent Wazuh administration experience, or with many clusters and integrations, often choose a partner for the inventory and verification work. Check the current removal syntax against the documentation for your installed 4.14 patch release before running commands in production.

How do we handle hundreds of stale agents without breaking things?

Work in batches rather than all at once. First export the agent list with status and last keep-alive details, group entries by owner and environment, then confirm each group with the owning team. Remove a small, low-risk batch first, check the dashboard, alerts and any downstream integration, and then continue. Keep a written record of every agent ID removed and the reason, so you can explain a gap later. For hosts that are disconnected but may return, consider marking them for review rather than deleting them immediately.

How do we find agents that have been disconnected for a long time?

Use the agent list from the Wazuh API or the agent_control and manage_agents tools to filter by connection status, then sort by last keep-alive time. Compare the results with your asset inventory, because an agent that has been silent for a long period may belong to a host that is still running but cannot reach the manager. Record the threshold you use for stale, since a short window can flag hosts on laptops or in maintenance cycles. Confirm the list with owners before any deletion.

What should a partner include in the scope for this work?

A partner scope should name the Wazuh deployments in scope, the agent counts and operating systems, the method for inventory and removal, and the owner confirmation process. It should also cover duplicate detection and key handling for rebuilt hosts, a rollback or recovery note for removed agents, verification steps on the dashboard and integrations, and a written record of what was removed. DeployOpen plans and delivers fixed-scope engagements with scope, deliverables and timelines agreed in writing before work starts, so ask for those items to be listed explicitly in the quote.

How do we avoid key conflicts when hosts are rebuilt?

Decide before a rebuild whether the old agent entry will be removed or reused. When a host is reinstalled and enrolls again, the new agent can appear as a duplicate or conflict with an existing key, so confirm the old entry is removed or the new registration follows your documented process. Include rebuild steps in your runbook, such as removing the old agent before reinstalling, and test the process on a non-production host first. Ask your team to confirm the exact enrollment behavior for your Wazuh version.

How DeployOpen scopes and delivers agent cleanup

DeployOpen treats agent cleanup as a scoped piece of work on a self-hosted Wazuh deployment in your infrastructure. We agree what gets removed, how stale and duplicate agents are identified and how key conflicts are avoided, then deliver the cleanup with written records your team can keep.

How we scope

  • Inventory the current agent list, including disconnected, duplicate and unidentified entries, before any removal is agreed
  • Agree in writing which decommission rules, disconnection thresholds and approval steps apply to your hosts
  • Confirm the Wazuh version in use and the CLI or API method your team is allowed to run in your change process

How we build

  • Run removals in a controlled order with a record of each agent ID, hostname and reason for removal
  • Check that rebuilt hosts re-enroll with new keys and that old keys no longer match active agents
  • Test the cleanup steps on a non-production manager or a copy of the agent list before running them on production

How we hand over

  • Document the cleanup procedure, the commands used and the verification checks, written for your own operators
  • Provide a list of removed agents, retained agents and any items your team must confirm with system owners
  • Leave a repeatable checklist for future decommissioning, duplicate detection and periodic stale-agent review

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts
  • Ongoing support, upgrades and periodic stale-agent reviews are available as a retainer
  • Ask for the written scope to list the hosts, environments and change windows covered before you approve the quote

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.