I’m trying to write a script and app shortcut to easily start and open a remote desktop session to a windows VM that I’m hosting on my PC with libvirt.
But I can’t seem to get any output when I try to list VMs with virsh list unless I run it as root. I’m not getting a “permission denied” error anywhere, just an empty list.
Do you guys know what I need to do to get this working?
Have you read the man page for virsh?
For the list command I see this
list
Syntax:
list [--inactive | --all]
[--managed-save] [--title]
{ [--table] | --name | --uuid | --id }
[--persistent] [--transient]
[--with-managed-save] [--without-managed-save]
[--autostart] [--no-autostart]
[--with-snapshot] [--without-snapshot]
[--with-checkpoint] [--without-checkpoint]
[--state-running] [--state-paused]
[--state-shutoff] [--state-other]
Prints information about existing domains. If no options are specified it prints out information about running domains.
When I did this it gets nothing
$ virsh list
Id Name State
------------------------------
But when I added the option it gives this
$ virsh list --all
Id Name State
------------------------------
- ubuntu18.04 shut off
Man pages are your friend.
Also, there are differences in the return when run with my regular user vs running it with sudo.
Your script may need to use sudo to achieve your goal.
Remember that you can give specific commands extra rights in the sudoers file.
Thanks @ilikelinux
I did not know the same answer.
Adding the entry you suggested to ~/.config/libvirt/libvirt.conf makes it so the return from ‘virsh list’ as my normal user returns the same as the command given as root.