1个

我想授予一个组安装软件的权限,而无需输入 root/sudo 密码。我在 Linux Mint 20.3 Cinnamon 上。

我创建了一个名为“basicsudo”的组。

我先打字

$ which apt-get  
/usr/bin/apt-get

然后

sudo visudo

然后我添加了以下行

%basicsudo ALL=(ALL) NOPASSWD: /usr/bin/apt-get install

/etc/sudoers.tmp

[...]
# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

%basicsudo ALL=(ALL) NOPASSWD: /usr/bin/apt-get install
# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

Groups and Users我使用菜单中的 GUI将组分配给用户。为了检查这个我跑了

$ groupname Alice 
Alice, basicsudo

从我的帐户。

当以 Alice 身份登录时,这是确认的

$ groups
Alice, basicsudo

但是当尝试以爱丽丝身份执行以下行时,我没有成功:

$ sudo apt-get install python3-pip  
[sudo] password for Alice:           
Sorry, user Alice is not allowed to execute '/usr/bin/apt-get    install python3-pip' as root on computername.

很明显 a) 系统提示我输入密码 b) 尽管输入了密码但我无法执行它。

这样做的正确方法是什么?

1 个回答   正确答案

2个

改变:

%basicsudo ALL=(ALL) NOPASSWD: /usr/bin/apt-get install

%basicsudo ALL=(ALL) NOPASSWD: /usr/bin/apt-get install *

来自man sudoers:

命令名是一个完全限定的文件名,其中可能包含 shell 样式的通配符......一个简单的文件名允许用户使用他们想要的任何参数运行命令。但是,您也可以指定命令行参数(包括通配符)。或者,您可以指定“”以指示该命令只能在没有命令行参数的情况下运行...

如果 Cmnd 具有关联的命令行参数,则 Cmnd 中的参数必须与用户在命令行中给出的参数完全匹配(或者匹配通配符,如果有的话)...

所以:

Sudoers意义
%basicsudo ALL= /usr/bin/apt-get ""apt-get不带参数运行
%basicsudo ALL= /usr/bin/apt-getapt-get使用任何参数运行
%basicsudo ALL= /usr/bin/apt-get installapt-get install没有更多的参数运行
%basicsudo ALL= /usr/bin/apt-get install *apt-get install使用更多参数运行

您的答案


来自 https://unix.stackexchange.com/questions/690749/how-to-enable-sudo-privileges-for-user-group-to-apt-get-install-anything