【问题标题】:Write a linux script that can be run as root/sudo编写一个可以作为 root/sudo 运行的 linux 脚本
【发布时间】:2011-10-07 17:32:35
【问题描述】:

我想做的是:

  • 编写一个脚本来用 yum 安装一些软件:yum install whatever
  • 此脚本将由没有 root 或 sudo 权限的用户执行

我不反对将root密码放入脚本中,我只是不知道该怎么做,我的意思是我的脚本可能如下所示:

sudo -u root -p password
yum install whatever

第一行是我不知道自己在做什么的地方,我了解将根凭据放在这里所涉及的安全风险,但这并不重要。

【问题讨论】:

    标签: linux shell


    【解决方案1】:

    The full power is described here:

    sudo 的灵活性被广泛低估了。这会导致非常糟糕的做法(例如sudo su - canon-ball 手术方法)。

    更好的方法是专门允许您打算允许的命令不使用密码

    phill = NOPASSWD: /bin/ls, /usr/bin/lprm
    

    您可以选择为来自特定主机的特定用户执行此操作,该主机以特定管理员用户身份运行。您甚至可以阻止用户将 shell 转义符作为参数传递。您可以使 sudo 阻止启动的程序动态执行进一步的应用程序等。您将需要read the man-page for sudoers (and be sure to read the procedures for editing this special file!)

    这里是一些小事,(from here):

    User_Alias     OPERATORS = joe, mike, jude
    Runas_Alias    OP = root, operator
    Host_Alias     OFNET = 10.1.2.0/255.255.255.0
    Cmnd_Alias     PRINTING = /usr/sbin/lpc, /usr/bin/lprm
    
    OPERATORS ALL=ALL
    #The users in the OPERATORS group can run any command from any terminal.
    
    linus ALL=(OP) ALL
    # The user linus can run any command from any terminal as any user in the OP group (root or operator).
    
    user2 OFNET=(ALL) ALL
    # user user2 may run any command from any machine in the OFNET network, as any user.
    
    user3 ALL= PRINTING
    # user user3 may run lpc and lprm from any machine.
    
    go2linux ALL=(ALL) ALL
    # user go2linux may run any command from any machine acting as any user. (like Ubuntu)
    
     If you want not to be asked for a password use this form
    go2linux ALL=(ALL) ALL NO PASSWD: ALL
    

    【讨论】:

      【解决方案2】:

      如果用户没有 sudo 权限,那么调用 sudo 是毫无用处的,因为它只会拒绝访问。另外:使用 sudo 将要求用户输入 root 密码,而是要求输入他自己的密码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-07
        • 1970-01-01
        • 2011-09-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-18
        • 1970-01-01
        相关资源
        最近更新 更多