Linux – virsh: failed to connect to hypervisor as user

centoslibvirtlinuxredhat

I'm currently running a RHEL 7.7 operating system.

I was trying to setup minkube environment using kvm2 driver, so what happens is that minikube starts pretty, but with some errors during the startup .

The error is the following:

'kvm2' driver reported an issue: /bin/virsh domcapabilities --virttype kvm failed:
error: failed to connect to the hypervisor
error: Cannot recv data: Connection reset by peer

So i start to investigate, and first what i did i tried to run the virsh command on the command line getting the same identical error, so second thing i tried is to run this command with sudo, and in this case it worked.

So i think it has to be a permission problem, but still i'm failing to solve this issue (i would like to launch minikube as user without having to use sudo).

What i tried so far:

  1. Add my user in the group libvirt – Still failing
  2. Add my user in the groupos: kvmuser qemu and kvm – Still failing
  3. Updated the libvirtd.conf file with the following configuration:
unix_sock_group = "libvirt"
unix_sock_ro_perms = "0777"
unix_sock_rw_perms = "0770"
unix_sock_dir = "/var/run/libvirt"

  1. Checked the policykit rule, that was already present with this content:
polkit.addRule(function(action, subject) {
    if (action.id == "org.libvirt.unix.manage"
            && subject.local
            && subject.active
            && subject.isInGroup("wheel")) {
        return polkit.Result.YES;
    }
});

So i tried to add my user in the wheel group, still same problem

  1. Addedmy user also in the systemd-network (here i started just to random stuff lol :D) same problem.
  2. Disabled selinux – same problem.

So i searched everywhere and can't find the solution to my problem, soomeone that maybe has managedo to solve it?

I just want to run vish command as a normal user.

Best Answer

So after all the struggle (And btw probably adding the user to the right groups was part of the correct configuration), i was still missing one thing to get it works as a user.

Apparently it needs the following environment variable to be exported:

export LIBVIRT_DEFAULT_URI=qemu:///system

After that export if the user is in an allowed group for libvirt, all commands start to work.