如何给Linux用户sudo访问权限?

Ada*_*ani 55 linux sudo

我试图让sudo访问我的一个用户.我应该在终端输入什么?

Igo*_*bin 67

您需要运行visudo并在它打开的编辑器中写入:

igor    ALL=(ALL) ALL
Run Code Online (Sandbox Code Playgroud)

该行向用户授予所有权限igor.

如果您希望permit只运行某些命令,则需要在行中列出它们:

igor    ALL=(ALL) /bin/kill, /bin/ps
Run Code Online (Sandbox Code Playgroud)


Lev*_*sky 57

这个答案将满足您的需求,但通常您不会添加特定的用户名sudoers.相反,您有一 sudoers,只需在需要时将您的用户添加到该组.这样visudo,在sudo向用户授予权限时,您不需要多次使用.

如果您使用的是Ubuntu,该组很可能已经设置并调用admin:

$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
Run Code Online (Sandbox Code Playgroud)

...

# 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

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
Run Code Online (Sandbox Code Playgroud)

在其他发行版中,比如Arch和其他一些发行版,它通常被调用wheel,你可能需要设置它:Arch Wiki

要在具有"sudo"的命令之前为wheel组中的用户提供完全root权限,请取消注释以下行:%wheel ALL =(ALL)ALL

另请注意,在大多数系统visudo上将读取EDITOR环境变量或默认使用vi.所以,你可以尝试做EDITOR=vim visudo使用vim作为编辑器.

要将用户添加到组,您应该运行(以root用户身份):

# usermod -a -G groupname username
Run Code Online (Sandbox Code Playgroud)

groupname你的小组在哪里(比方说,adminwheel),username是用户名(比方说john).