Thu, March 8, 2018 ยท 1 min read

fixing polkit authentication when accessing libvirt as non root user remotely

fixing polkit authentication when accessing libvirt as non root user remotely

kvm command line tool virsh when access remotely will ask for authentication, which is quite annoying at times to fix this we can add a polkit rule to allow users to access libvirt daemon

==== AUTHENTICATING FOR org.libvirt.unix.manage ===
System policy prevents management of local virtualized systems
Authenticating as: cipher
Password:
==== AUTHENTICATION COMPLETE ===
Id Name State
----------------------------------------------------
  1. create a file called 80-libvirt-manage.rules at /etc/polkit-1/rules.d/
#cd /etc/polkit-1/rules.d/
#ll
-rw-r--r--. 1 root root 974 Aug 4 2017 49-polkit-pkla-compat.rules
-rw-r--r--. 1 root root 326 Jan 15 2014 50-default.rules
#touch 80-libvirt-manage.rules

add below code to the file

polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage" && subject.local && subject.active && subject.isInGroup("wheel")) {
return polkit.Result.YES;
}
});

save and restart polkitd daemon

  1. Add user to libvirt group
# usermod -aG libvirt cipher
#newgrp libvirt

Now we can access libvirt without authentication.

$virsh list --all
Id Name State
----------------------------------------------------