需要允许用户重新启动 bind9

Jas*_*son 3 bind start

我想让 www-data 用户能够使用此命令重新启动 bind9

服务 bind9 重启

目前,他们可以执行它,它将停止 bind9 但不会再次重新启动它,抱怨权限不允许对“named”文件进行 chmod。

你能指出我需要做的事情的方向吗

更新

好的,所以我按照要求将该行添加到 sudoers。

www-data      ALL=NOPASSWD: /etc/init.d/bind9
Run Code Online (Sandbox Code Playgroud)

它仍然存在一些问题:

root@LAMPREY:~# su www-data
$ service bind9 restart
 * Stopping domain name service... bind9                                        rndc: error: none:0: open: /etc/bind/rndc.key: permission denied
rndc: could not load rndc configuration
                                                                         [ OK ]
 * Starting domain name service... bind9                                        chmod: changing permissions of `/var/run/named': Operation not permitted
$ exit
Run Code Online (Sandbox Code Playgroud)

然后我还尝试运行另一个命令

/etc/init.d/bind9 restart
 * Stopping domain name service... bind9                                        rndc: error: none:0: open: /etc/bind/rndc.key: permission denied
rndc: could not load rndc configuration
                                                                         [ OK ]
 * Starting domain name service... bind9                                        chmod: changing permissions of `/var/run/named': Operation not permitted
$ exit
Run Code Online (Sandbox Code Playgroud)

结果相同

Sha*_*dur 7

要回答这三个以上:sudo当血淋淋的矫枉过正rndc已经拥有你所需要的能力,再加上选项重装域名服务器,其他比在本地主机上的一个。

该脚本rndc-confgen将为您生成一个 rndc.conf 文件,您可以将其保存 /etc/rndc.conf并使其可读www-data

shadur@Romulus:~$ rndc-confgen 
# Start of rndc.conf
key "rndc-key" {
    algorithm hmac-md5;
    secret "zGHUrg0X5Id4rn27A0Nb9A==";
};

options {
    default-key "rndc-key";
    default-server 127.0.0.1;
    default-port 953;
};
# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndc-key" {
#   algorithm hmac-md5;
#   secret "zGHUrg0X5Id4rn27A0Nb9A==";
# };
# 
# controls {
#   inet 127.0.0.1 port 953
#       allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf
Run Code Online (Sandbox Code Playgroud)

然后可以添加注释掉的部分/etc/bind/named.conf,以告诉服务器它应该正确响应该密钥(当您运行rndc-confgen.

完成上述操作并重新启动绑定一次后,www-data 用户应该能够通过rndc命令发出绑定命令。

rndc restart将完全重启服务器; rndc reconfig将导致它重新加载其named.conf文件; rndc reload将检查并重新加载所有区域; rndc reload <zone>将检查并重新加载。

还有其他命令;您可以通过简单地键入rndc而无需任何命令来获取列表。

当手术刀可以使用时,不要使用链锯;sudo当您甚至不需要成为 root 时,请不要使用。


use*_*517 6

为什么您不想授予用户访问权限sudo以运行此特定命令?这正是 sudo 的设计目的。

添加

www-data somehost= /sbin/service bind9 restart
Run Code Online (Sandbox Code Playgroud)

将授予用户 www-dataservice bind9 restart在某个主机上运行(并且仅该命令)的权限。

  • 你使用 `visudo` 来编辑 `sudoers` 文件 (3认同)