AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1589696
Accepted
j4nd3r53n
j4nd3r53n
Asked: 2020-10-01 02:33:38 +0800 CST2020-10-01 02:33:38 +0800 CST 2020-10-01 02:33:38 +0800 CST

让单个用户在没有 sudo 密码的情况下执行命令

  • 772

我已经搜索并找到了很多答案,但我仍然无法让它工作。这是在 debian 9 系统上 - 我在配置文件中创建了一个别名和一个 shell 函数:

alias lscron='sudo crontab -u biuser -l'

function edcron
{
  lckf=~biuser/edcron
  if [[ -f $lckf ]]
  then
    echo $(cat $lckf) is editing
  else
    echo $(id -nu) > $lckf
    sudo crontab -u biuser -e
    rm $lckf
  fi
}

它们按预期工作,但要求输入密码。我想让一些用户无需密码即可运行这些命令,所以我添加了如下内容/etc/sudoers:

analytics root = cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# 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

some.user ALL = NOPASSWD: /usr/bin/crontab -u biuser -e, /usr/bin/crontab -u biuser -l

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

#includedir /etc/sudoers.d

我没有收到任何错误,但它要求输入密码;我如何让它工作?

编辑

Matching Defaults entries for some.user on analytics:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User some.user may run the following commands on analytics:
    (ALL : ALL) ALL
    (root) NOPASSWD: /usr/bin/crontab -u biuser -e, /usr/bin/crontab -u biuser -l
    (ALL : ALL) ALL
sudo sudoers
  • 1 1 个回答
  • 164 Views

1 个回答

  • Voted
  1. Best Answer
    Kamil Maciorowski
    2020-10-01T04:38:46+08:002020-10-01T04:38:46+08:00

    当一个用户有多个条目匹配时,它们将按顺序应用。如果有多个匹配项,则使用最后一个匹配项(不一定是最具体的匹配项)。

    (来源)

    在您的情况下, “获胜”(ALL : ALL) ALL输出中的最后一个。sudo -l

    NOPASSWD在行后sudoers没有明确(ALL : ALL) ALL的,但有#includedir。这不是评论。必须有(ALL : ALL) ALL一些/etc/sudoers.d匹配的文件some.user。

    您的目标是(ALL : ALL) ALL在. 然后您的设置将起作用。NOPASSWDsudo -l -U some.user

    您可以在不更改文件的情况下sudoers.d通过将NOPASSWD行放在#includedir. 这样,每当该行匹配时,它肯定是最后一个匹配。

    • 2

相关问题

  • sudo 和环境变量在 Debian 和 Ubuntu 中的行为不同

  • 当多个单词时通过 sudo 执行命令失败

  • 仅为某些参数授予对命令的访问权限(chown 用于路径)

  • 从 sudo su 运行命令

  • 如何让debian apt正确找到包来安装sudo

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve