20

I installed virt-manager and I am unable to make it work.

I have tried some of the previously posted answers with no success. I've verified that:

  • The libvirt-bin package is installed
  • The libvirtd daemon has been started
  • I am a member of the libvirtd group
  • libvirt URI is: qemu:///system

This is the error I get when trying to run virt-manager:

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/connection.py", line 1027, in _open_thread
    self.vmm = self._try_open()
  File "/usr/share/virt-manager/virtManager/connection.py", line 1009, in _try_open
    flags)
  File "/usr/lib/python2.7/dist-packages/libvirt.py", line 102, in openAuth
    if ret is None:raise libvirtError('virConnectOpenAuth() failed')
libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission     denied
edwin
  • 3,799
  • 20
  • 33
New_to_Linux
  • 201
  • 1
  • 2
  • 3

6 Answers6

14

You may have to log out and log back in.

Assuming /etc/libvirt/libvirtd.conf has:

# Set the UNIX domain socket group ownership. This can be used to
# allow a 'trusted' set of users access to management capabilities
# without becoming root.
#
# This is restricted to 'root' by default.
unix_sock_group = "libvirtd"

# Set the UNIX socket permissions for the R/O socket. This is used
# for monitoring VM status only
#
# Default allows any user. If setting group ownership, you may want to
# restrict this too.
unix_sock_ro_perms = "0777"

# Set the UNIX socket permissions for the R/W socket. This is used
# for full management of VMs
#
# Default allows only root. If PolicyKit is enabled on the socket,
# the default will change to allow everyone (eg, 0777)
#
# If not using PolicyKit and setting group ownership for access
# control, then you may want to relax this too.
unix_sock_rw_perms = "0770"

It should work if your user is a member of the libvirtd group.

Check if your user is supposed to be in the group, example user vagrant:

$ cat /etc/group|grep $USER
vagrant:x:1000:
libvirtd:x:116:ubuntu,vagrant

If your user is not in the group, you'll need to add it:

$ sudo usermod -a -G libvirtd $USER

If your user was already in the group in /etc/group, then check the output of groups:

$ groups
vagrant libvirtd

If you don't see libvirtd, you'll need to log out and log back in.

melwitt
  • 141
1

On Ubuntu 22.04, you can easily add your user to specific groups such as kvm and libvirt using the following commands:

sudo usermod -aG kvm $USER 
sudo usermod -aG libvirt $USER

After executing these commands, it is necessary to either relog or restart your system for the changes to take effect.

For a sanity check to ensure that the changes have been successfully applied, you can open a terminal and type the command: groups. This will display a list of groups your user is a member of, allowing you to verify whether you have been added to the kvm and libvirt groups.

1

I had the same issue. Try this guide it's works for me. Don't forget relogin after add user to group 'libvirtd'

Zipun
  • 11
  • 1
0

I encountered this problem because I had two libvirtd groups.

When I installed qemu-kvm, group libvirtd did not exist, so it was created with arbitrary group ID 121:

ls -n /var/run/libvirt/libvirt-sock
srwxrwx--- 1 0 121 0 Oct  1 18:49 /var/run/libvirt/libvirt-sock

Later, my host joined NIS. I am a member of libvirtd, but the group ID is 1046:

id
uid=177(jmcgeheeiv) ...,1046(libvirtd),...

I am not a member of group 201, so I cannot write to socket /var/run/libvirt/libvirt-sock.

Updating the group ownership of /var/run/libvirt/libvirt-sock to the correct group number solved my problem:

sudo chgrp 1019 /var/run/libvirt/libvirt-sock
ls -n /var/run/libvirt/libvirt-sock
srwxrwx--- 1 0 1019 0 Oct  1 18:49 /var/run/libvirt/libvirt-sock

In this case, there is no need to log out and log in.

While the above solves the immediate problem, it violates infrastructure as code. The real solution is to rebuild the host, first creating group libvirtd with group ID 1046 consistent with NIS, and then installing qemu-kvm.

0

In my case the solution was to install on the KVM host sudo apt install qemu-system instead of sudo apt install --no-install-recommends qemu-system. I did not have to alter the default /etc/libvirt/libvirtd.conf. See also Debian KVM Wiki

0

Try to add this line to /etc/libvirt/libvirtd.conf

listen_tls = 0

then restart lirvirt by:

/etc/init.d/libvirt-bin restart
Alaa Ali
  • 31,535