Skip to content

How to use virsh-commands without sudo #30

Closed

Description

@Rosika2

Hi altogether,

I used to run Lubuntu 18.04.5 (bionic) but now - after a fresh install - I am using Lubuntu 20.04.1 (focal).

I noticed a difference between those distro versions as far as virsh-commands are concerned:

With bionic I could use the command virsh list --all and it listed the available VMs alright. Now with focal I get an empty list.
sudo virsh list --all works as desired and lists the VMs.

Doing a bit of research I found on https://serverfault.com/questions/803283/how-do-i-list-virsh-networks-without-sudo :

If virsh finds the environment variable VIRSH_DEFAULT_CONNECT_URI set, it will try this URI by default. Use of this environment variable is, however, deprecated now that libvirt supports LIBVIRT_DEFAULT_URI itself.

On my system it seems none of those variables are set.

One of the possible solutions was:

it's easier to specify the connection string directly in virsh command (at least when writing a script).

This I tried and typed the following in my terminal:

rosika@rosika-10159 ~> LIBVIRT_DEFAULT_URI=qemu:///system virsh list --all
 Id   Name          State
------------------------------
 -    ubuntu18.04   shut off

rosika@rosika-10159 ~> LIBVIRT_DEFAULT_URI=qemu:///system virsh start ubuntu18.04
Domain ubuntu18.04 started

rosika@rosika-10159 ~> LIBVIRT_DEFAULT_URI=qemu:///system virsh list --all
 Id   Name          State
-----------------------------
 9    ubuntu18.04   running

rosika@rosika-10159 ~> LIBVIRT_DEFAULT_URI=qemu:///system virsh shutdown ubuntu18.04
Domain ubuntu18.04 is being shutdown

rosika@rosika-10159 ~> LIBVIRT_DEFAULT_URI=qemu:///system virsh list --all
 Id   Name          State
------------------------------
 -    ubuntu18.04   shut off

This way it works without sudo which is great.

I also noticed that setting the environment variable VIRSH_DEFAULT_CONNECT_URI=qemu:///system instead of LIBVIRT_DEFAULT_URI=qemu:///system still works.

As I´m using fish as my default shell it´s easy to retrieve the respective commands from fish_history. No need to memorize it or edit /etc/libvirt/libvirt.conf for that matter. So this would be a good solution for me.

My question is:

Is my method of doing it right? All I want to achieve is using virsh-commands without sudo.

Many thanks in advance.
Greetings from Rosika

Activity

  1. repo-lockdown commented on Jan 26, 2021

    @repo-lockdown

    Thank you for your interest in the libvirt project.

    Since this repository is a read-only mirror of the project's master repostory hosted on GitLab, issues opened here are not processed.

    We kindly request that new issues are reported to

    https://gitlab.com/libvirt/libvirt/-/issues/new

    Thank you for your time and understanding.

  2. locked and limited conversation to collaborators on Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions