You are not logged in.

#1 2024-04-16 13:46:58

AndreyFrantsevich
Member
Registered: 2023-10-30
Posts: 16

Run command (virsh) SUDO without passwd.

Hello, I need to manage VM from script, so I added this rows in visudo

andrew ALL = NOPASSWD: /usr/bin/virsh start win11 
andrew ALL = NOPASSWD: /usr/bin/virsh list --all

sudo -lU andrew:


User andrew may run the following commands on archlinux:
    (root) NOPASSWD: /usr/bin/virsh start win11
    (root) NOPASSWD: /usr/bin/virsh list --all
    (ALL) ALL

BUT, when I run this from bash

 
sudo virsh start win11
sudo virsh list --all 

It requests the password.

What am I doing wrong?

Last edited by AndreyFrantsevich (2024-04-16 13:52:59)

Offline

#2 2024-04-16 14:15:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,778
Website

Re: Run command (virsh) SUDO without passwd.

Have you logged back in before attempting those commands?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2024-04-16 14:22:54

GerBra
Forum Fellow
From: Bingen/Germany
Registered: 2007-05-10
Posts: 207

Re: Run command (virsh) SUDO without passwd.

You have to enter exactly the same command as defined in /etc/sudoers:

Your user is only allowed to use:
/usr/bin/virsh
with options: start win11 and list --all

It's not allowed to use "virsh" without the full path prefix.

This is a security feature when using sudo.

Offline

#4 2024-04-16 14:24:38

AndreyFrantsevich
Member
Registered: 2023-10-30
Posts: 16

Re: Run command (virsh) SUDO without passwd.

Trilby wrote:

Have you logged back in before attempting those commands?

who:

andrew   tty7         2024-04-16 16:39 (:0)
andrew   pts/4        2024-04-16 17:22
andrew   pts/3        2024-04-16 17:19

Offline

Board footer

Powered by FluxBB