Use virt-manager as a non-root user on Linux

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatshut down

Hello everyone. I have used KVM for a long time. Every time I try to use virt-manager as a non-root user, I have to enter the sudo password. This is not a problem, but if you use virt-manager most of the time, it may be boring and annoying.

For KVM installation, please refer to the guide below.

How to install KVM on RHEL/CentOS 8, Fedora, Arch Linux, CentOS, Ubuntu/Debian, SLES

I will show you a simple way to use Virus manager As a non-root user, just create a libvirt group and add a standard user account to it. Without wasting too much time, let us dive in.

To use virt-manager as a non-root user, perform the following steps:

Step 1-Create the UNIX group to be used

First check whether the group already exists, if it does not exist, create it

sudo getent group | grep libvirt

Some distributions may be using libvirtd.

sudo getent group | grep libvirtd

If it does not exist, add it as a system group.

sudo groupadd --system libvirt

Step 2-Add user account to libvirt group

Now that the group is available, add your user account to the group.

sudo usermod -a -G libvirt $(whoami)newgrp libvirt

Verify that the user has been added to the libvirt group.

$ id $(whoami)uid=1000(jmutai) gid=1000(jmutai) groups=1000(jmutai),998(wheel),992(kvm),988(storage),968(libvirt),108(vboxusers)

Step 3-Edit libvirtd configuration file to add groups

Open the file /etc/libvirt/libvirtd.conf for editing.

sudo vim /etc/libvirt/libvirtd.conf

Set the UNIX domain socket group ownership to libvirt (near line 1) 85)

unix_sock_group = "libvirt"

Set UNIX socket permissions for R/W sockets (near line 1) 102)

unix_sock_rw_perms = "0770"

After making the changes, restart the libvirt daemon.

sudo systemctl restart libvirtd.service

Check the service status.

$ systemctl status libvirtd.service     ● libvirtd.service - Virtualization daemon    Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: disabled)    Active: active (running) since Fri 2019-04-19 08:48:13 EAT; 1h 16min ago      Docs: man:libvirtd(8)    Main PID: 31709 (libvirtd)     Tasks: 26 (limit: 32768)    Memory: 64.7M    CGroup: /system.slice/libvirtd.service            ├─  754 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leases>            ├─  755 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leases>            ├─  777 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/docker-machines.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvir>            ├─  778 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/docker-machines.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvir>            ├─25924 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/vagrant-libvirt.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvir>            ├─25925 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/vagrant-libvirt.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvir>            ├─25959 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/fed290.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leasesh>            ├─25960 /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/fed290.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leasesh>            └─31709 /usr/bin/libvirtd

Step 4-Start virt-manager

Start Virtual Machine Manager from the command line or “Start” menu.

$ virt-manager

You should be able to create the VM without permission errors.

You should be able to use virt-manager as a non-root user.If not, try to read libvirtd.conf File to view relevant parts for modification.

in conclusion

We have followed simple steps and introduced how to use virt-manager as a non-root user. You may have to install the KVM virtualization package group to get tools including virt-manager.

Here are some of our guides to help you get started

Use Vagrant with Libvirt on Linux.

How to configure VM on KVM using Terraform

How to create a CentOS/Fedora/RHEL VM template on KVM

RHEL and CentOS Kickstart on KVM automatic installation using virt-install

Further reading:

Master KVM virtualization

Virtualization basics, second edition

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatshut down