Dmitry,
The error you are seeing:
2026/02/18 10:15:05 wazuh-agent: ERROR: Duplicate agent name: AppSRV. Unable to add agent (from manager)
means that the Wazuh manager already has an agent registered with the name AppSRV. Even if Windows was reinstalled, and the client.keys file was cleared on the server, but the manager still detects a duplicate agent name during enrollment.
In Wazuh, agent names must be unique. It is not possible to rename an agent after it has been enrolled. The agent name is defined only during the enrollment process. If another agent with the same name already exists in the manager database, enrollment will fail with the duplicate name error.
To resolve this issue, you need to re-enroll the agent using a different name.
You can define the agent name during installation or enrollment using the deployment variable: WAZUH_AGENT_NAME
https://documentation.wazuh.com/current/user-manual/agent/agent-enrollment/deployment-variables/index.html
For example, during installation on Windows, set the variable so the agent registers with a unique name instead of AppSRV.
Alternatively, you can define the agent name in the ossec.conf file on the Windows agent before starting the service.
Edit: C:\Program Files (x86)\ossec-agent\ossec.conf
Add the following block:
<enrollment>
<agent_name>YOUR_NEW_AGENT_NAME/agent_name>
</enrollment>
Reference:
https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/client.html#enrollment
After saving the file, start the Wazuh agent service. The agent will request a new key from the manager and register with the new name.
Please note that when you re-enroll the agent with a new name, it will receive a new agent ID and a new key. Any previous association with the old agent entry will not be preserved.
If you still encounter issues, please confirm whether there is still an existing agent entry with the name AppSRV on the manager by running on the manager:
/var/ossec/bin/agent_control -l
If AppSRV is still listed, you can remove it before re-enrollment using:
/var/ossec/bin/manage_agents -r <WAZUH_AGENT_ID>
https://documentation.wazuh.com/current/user-manual/agent/agent-management/remove-agents/remove.html
Then delete the old entry and enroll the agent again with a unique name.
This will ensure the duplicate name conflict is fully resolved.
Based on the logs, the problem is that the endpoint is still using an old client key, which belongs to agent ID 022.
On the manager, you removed the agent, but the Windows endpoint still has its previous client.keys content. Because of that, the agent continues using the old key, and the manager reports:
Agent key already in use: agent ID '022' Duplicate name 'APPSRV2026', rejecting enrollment. Agent '022' can't be replaced since it is not disconnected.To fully fix the issue, the agent must be removed and reinstalled on the endpoint, not only removed from the manager.
Please do the following on the Windows system:
Uninstall the Wazuh agent completely
Install the agent again
Before starting the service, define the new agent name in ossec.conf:
<enrollment>
<agent_name>APPSRV2026</agent_name>
</enrollment>
or set it via WAZUH_AGENT_NAME during installation.
When the agent is reinstalled, it will generate a new client.key, and the manager will accept it.
If reinstalling does not resolve it, please share:
I can then reproduce the issue on my side.
It seems that no events are being discarded, and the issue is caused by older agent entries still existing on the manager with the same client key or agent name.
Uninstall the Wazuh agent from the Windows system completely using:
msiexec.exe /x wazuh-agent-4.14.3-1.msi /qn
Remove the corresponding agent entry from the Wazuh manager, including any duplicate or previously connected entries:
/var/ossec/bin/manage_agents -r <WAZUH_AGENT_ID>
Restart the Wazuh manager and confirm that no old agent ID remains.
Then, verify on the Windows endpoint that no old Wazuh files or configurations are left.
Reinstall the Wazuh agent on the Windows endpoint with a unique agent name. You can set it directly in the configuration:
or by using the installation variable:
If there is still a connection issue, check the manager database to see if any leftover records exist:
sqlite3 /var/ossec/queue/db/global.db
SELECT id, name, register_ip FROM agent;
--
You received this message because you are subscribed to a topic in the Google Groups "Wazuh | Mailing List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wazuh/SlCrtPHCoyA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wazuh+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/wazuh/1abda69e-536e-409c-b5a8-bb9d695e4f9en%40googlegroups.com.
Dmitry,
Your issue is not caused by duplicate names or leftover keys anymore. The behaviour you see comes from a stale TCP connection on the manager side.
When Windows was reinstalled, the previous Wazuh agent connection did not close cleanly. Windows Server 1809 often shuts down without sending FIN/RST packets, especially during updates. Because of that, the manager still keeps the old TCP connection for that agent ID in an established state.
As long as that stale connection exists in wazuh-remoted memory, the manager will think agent ID 032 is still connected, so Authd will not replace it and will continue to reject the new enrollment with messages like:
Agent key already in use: agent ID '032'
Duplicate name 'AppServ', rejecting enrollment. Agent '032' can't be replaced since it is not disconnected.
Removing the agent with manage_agents does not clear that in-memory connection. The manager needs a full restart to drop the stale state.
Do the following cleanly:
Stop the entire Wazuh manager: systemctl stop wazuh-manager
Then, remove the agent via manager_agents
Edit or remove the specific line for the agent if needed: /var/ossec/etc/client.keys
On the Windows side, remove the agent, and delete the folders
Start the manager again: systemctl start wazuh-manager
Then reinstall the agent and name it uniquely
Start the agent service and allow it to enroll again.
After restarting the manager, the stale TCP connection will be removed, and the manager will accept the new key immediately.
For the future, the recommended practice is to stop the Wazuh agent service on the Windows host before performing a Windows reinstallation, so the TCP connection is closed gracefully before the OS shuts down.
Dmitry,
The changes you tried will not fix this issue. The problem is that the Wazuh manager still thinks the old agent connection is active, even though the Windows machine was reinstalled. Because of this, the manager will not accept the new agent or new key.
The only way to clear that old connection is to restart the Wazuh manager because the stuck connection is stored in memory, not in the database or configuration.
Stop the entire Wazuh manager: systemctl stop wazuh-manager
Then remove the agent using manage_agents.
Edit or remove the specific line for the agent if needed: /var/ossec/etc/client.keys
On the Windows side, remove the agent and delete the folders.
Start the manager again: systemctl start wazuh-manager
Then reinstall the agent and give it a unique name.
Start the agent service and allow it to enroll again.
After the manager restarts, the old connection will be gone, and your agent should enroll correctly.
If the problem still appears after doing this, let me know. I will discuss this with the team again