How to Completely Disable the ‘lxd-agent’ Daemon in Ubuntu Server

When running LXD (the next-generation system container and virtual machine manager) on an Ubuntu Server, the lxd-agent daemon is typically injected into the guest virtual machines. This agent facilitates communication between the LXD host and the guest OS, enabling features like executing commands inside the VM from the host via lxc exec, or pushing/pulling files. However, if you are running highly secure, isolated VMs and you want to enforce strict network-only access (e.g., forcing all administrators to use SSH rather than bypassing the network stack via the hypervisor socket), you must disable the agent inside the guest.

This guide explains how to completely disable the lxd-agent daemon within an Ubuntu Server guest virtual machine.

Stop and Disable the LXD Agent

To ensure the VM drops all hypervisor-level backdoor communication and relies solely on its standard network interfaces, we must halt the agent and mask it via systemd.

  1. Log into your Ubuntu Server guest VM (not the LXD host) via SSH using an account with sudo privileges.
  2. First, stop the active service to terminate the hypervisor communication socket immediately:
    sudo systemctl stop lxd-agent.service
  3. Next, disable the service so it does not attempt to reconnect to the host during the next boot:
    sudo systemctl disable lxd-agent.service
  4. To guarantee that no other dependent service or cloud-init script can accidentally invoke the agent, mask the unit entirely:
    sudo systemctl mask lxd-agent.service

Verify the Isolation

By masking the service, you have effectively severed the VM from the LXD host’s out-of-band management channel without removing the underlying virtio drivers.

To verify the lockdown is absolute, log out of the VM and return to the LXD host server. Attempt to execute a command inside the guest VM using the LXC client: lxc exec <vm-name> -- bash. The command will fail, returning an error stating that the LXD agent is not running or the connection was refused. You have now successfully enforced strict, network-only (SSH) administration for that specific virtual machine, hardening its isolation boundary.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.