Allow users to run virsh and manage VMs

https://libvirt.org/aclpolkit.html
https://major.io/2015/04/11/run-virsh-and-access-libvirt-as-a-regular-u…
https://www.poftut.com/use-virt-manager-libvirt-normal-user-without-roo…

Defining custom rules requires creation of a file in the /etc/polkit-1/rules.d directory with a name chosen by the administrator (100-libvirt-acl.rules would be a reasonable choice). See the polkit(8) manual page for a description of how to write these files in general.

We're going to allow members of the libvirt group to manage VM's:

mkdir /etc/polkit-1/rules.d
vi /etc/polkit-1/rules.d/100-libvirt-acl.rules

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

NB. Add to user's .bashrc:

export LIBVIRT_DEFAULT_URI=qemu:///system

 

Add bash completion library:

Download the bash completion library: virsh_bash_completion

How to use it: Copy virsh_bash_completion file to /etc/bash_completion.d/ then restart bash.

(Source)

 

Category