Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

B.2.2. Failed to connect socket ... : Permission denied

Symptom
When running a virsh command, the following error (or similar) appears:
$ virsh -c qemu:///system list
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
error: failed to connect to the hypervisor
Investigation
Without any host name specified, the connection to QEMU uses UNIX sockets by default. If there is no error running this command as root, the UNIX socket options in /etc/libvirt/libvirtd.conf are likely misconfigured.
Solution
To connect as a non-root user using UNIX sockets, configure the following options in /etc/libvirt/libvirtd.conf:
unix_sock_group = <group>
unix_sock_ro_perms = <perms>
unix_sock_rw_perms = <perms>

Note

The user running virsh must be a member of the group specified in the unix_sock_group option.