# Uninstallation

We understand that LinuxGuard may not be the right fit for every environment. When you decide to remove the agent, we ensure a complete and clean removal process that leaves no traces behind.

## Complete Cleanup

The LinuxGuard uninstallation process is designed to completely remove the agent and all associated components from your system:

* **Agent unenrollment**: The agent automatically unenrolls from your tenant before removal
* **Service cleanup**: The agent service is stopped and disabled
* **File removal**: All configuration files, state data, and logs are removed
* **User cleanup**: The dedicated `linuxguard` user and group accounts are removed
* **Complete removal**: No traces of the agent remain on your system

## Uninstallation Methods

The uninstallation process varies slightly depending on your Linux distribution's package manager.

### Debian-based Systems

For Debian, Ubuntu, and other Debian-based distributions:

**Remove the agent (keeps configuration files):**

```bash
sudo apt remove linuxguard-agent
```

**Remove the agent and all configuration files (complete cleanup):**

```bash
sudo apt purge linuxguard-agent
```

The `purge` command ensures complete removal of all agent files, including:

* Configuration files in `/etc/linuxguard/`
* State files in `/var/lib/linuxguard/`
* Log files in `/var/log/linuxguard/`
* Runtime files in `/var/run/linuxguard/`
* The `linuxguard` user and group accounts

### RedHat-based Systems

For RHEL, CentOS, Fedora, and other RedHat/YUM-based distributions:

**Remove the agent:**

```bash
sudo dnf remove linuxguard-agent
```

Or for older systems using YUM:

```bash
sudo yum remove linuxguard-agent
```

On RedHat-based systems, the `remove` command automatically performs a complete cleanup, removing all agent files, configuration, and user accounts.

### Alpine-based Systems

For Alpine Linux:

**Remove the agent:**

```bash
sudo apk del linuxguard-agent
```

The Alpine package manager automatically removes all agent files and performs complete cleanup.

## What Happens During Uninstallation

The uninstallation process follows these steps:

1. **Pre-removal cleanup**:
   * The agent automatically unenrolls from your LinuxGuard tenant
   * The agent service is stopped
   * The agent service is disabled to prevent it from starting on boot
2. **Package removal**:
   * The agent package is removed from your system
   * All agent binaries and files are removed
3. **Post-removal cleanup** (on Debian-based systems with `purge`):
   * All configuration directories are removed (`/etc/linuxguard/`)
   * All state directories are removed (`/var/lib/linuxguard/`)
   * All log directories are removed (`/var/log/linuxguard/`)
   * All runtime directories are removed (`/var/run/linuxguard/`)
   * The `linuxguard` user account is removed
   * The `linuxguard` group account is removed

## Verification

After uninstallation, you can verify that the agent has been completely removed:

```bash
# Check if the agent binary is removed
which linuxguard-agent

# Verify the agent user no longer exists
id linuxguard

# Check if agent directories are removed
ls -la /etc/linuxguard
ls -la /var/lib/linuxguard
ls -la /var/log/linuxguard

# Verify the service is removed
systemctl status linuxguard-agent
```

All of these commands should indicate that the agent and its components have been removed.

## Removing the Repository (Optional)

If you no longer need the LinuxGuard repository on your system, you can remove it:

### Debian-based Systems

```bash
# Remove the repository file
sudo rm /etc/apt/sources.list.d/linuxguard.list

# Remove the GPG key
sudo rm /etc/apt/trusted.gpg.d/linuxguard.gpg

# Update package cache
sudo apt update
```

### RedHat-based Systems

```bash
# Remove the repository file
sudo rm /etc/yum.repos.d/linuxguard.repo

# Or for DNF
sudo rm /etc/dnf/repos.d/linuxguard.repo

# Clean package cache
sudo dnf clean all
# Or
sudo yum clean all
```

### Alpine-based Systems

```bash
# Remove the repository from /etc/apk/repositories
sudo sed -i '/linuxguard/d' /etc/apk/repositories

# Update package index
sudo apk update
```

## Container Uninstallation

If you installed the agent in a container, simply remove the container:

```bash
# Docker
docker stop <container-name>
docker rm <container-name>

# Kubernetes
kubectl delete pod <pod-name>
```

If you used volumes for persistence, you may also want to remove those:

```bash
# Docker
docker volume rm linuxguard-data linuxguard-logs

# Kubernetes volumes are automatically cleaned up when pods are deleted
```

## Tenant Cleanup

After removing the agent from your systems, you may want to:

1. **Remove the agent from your console**: The agent will automatically disappear from your console after unenrollment, but you can also manually remove it if needed
2. **Review your tenant**: Consider whether you want to keep your tenant account active or contact <sales@linuxguard.io> to close your account

## Need Help?

If you encounter any issues during uninstallation or have questions about the removal process, our support team is here to help:

* **Email**: <support@linuxguard.io>
* **Available**: 24/7

We're committed to making the uninstallation process as smooth and complete as possible.

***

**Related**: [Installation](/how-to-guides/how-to/installation.md) | [Troubleshooting](/troubleshooting.md) | [Support](/support.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.linuxguard.io/how-to-guides/how-to/uninstallation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
