Allow virsh as a normal user on Debian Jessie

Debian Jessie has migrated libvirt to use polkit which means the normal advice of “add your user to libvirt and kvm groups” doesn’t work for virsh. There doesn’t seem to be any documentation about the change either. After a bit of head scratching and googling the following fixes the problem and allows members of the libvirt group to use virsh.

You need to create a local policykit access list, this example allows all members of the libvirt group to manage libvirt

/etc/polkit-1/localauthority/50-local.d/50-libvirt-virsh-access.pkla
[libvirt Management Access]
Identity=unix-group:libvirt
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes

You also need to configure virsh to connect to libvirtd running on the local system by default, to do this add these lines to .bash_profile to add it to your bash shell environment.

.bash_profile
if test -x $(which virsh); then
export LIBVIRT_DEFAULT_URI=qemu:///system
fi

http://www.linuxsysadmintutorials.com/configure-polkit-to-run-virsh-as-a-normal-user/

https://libvirt.org/auth.html#ACL_server_polkit