允许用户在没有密码的情况下使用 sudo

Tho*_*ard 16 sudo

在沙箱 VM 环境中,我设置了 Ubuntu Linux,它有防火墙,无法从本地系统外部访问。因此,在该 VM 上,我想为管理用户(我设置的)提供使用 sudo 运行任何内容而无需密码的能力。

虽然我知道这并不安全,但这个虚拟机并不是一直都在运行,并且需要我的个人密码才能运行。所以即使这不是“安全”,有没有办法获得所需的功能?

Ulr*_*gel 23

来自man sudoers

   NOPASSWD and PASSWD

   By default, sudo requires that a user authenticate him or herself
   before running a command.  This behavior can be modified via the
   NOPASSWD tag.  Like a Runas_Spec, the NOPASSWD tag sets a default for
   the commands that follow it in the Cmnd_Spec_List.  Conversely, the
   PASSWD tag can be used to reverse things.  For example:

    ray  rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

   would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm
   as root on the machine rushmore without authenticating himself.
Run Code Online (Sandbox Code Playgroud)

另一个标签是ALL,允许用户 ray 在没有密码的情况下在任何主机上运行任何命令,您可以使用:

ray ALL= NOPASSWD: ALL
Run Code Online (Sandbox Code Playgroud)

  • 这个答案描述的配置文件是`/etc/sudoers`。您不能像普通配置文件那样编辑它,而应该使用 `visudo` 命令(以 root 身份)。 (2认同)