如何允许非sudoers用户运行执行root操作的脚本

Supouse我有一个目录/opt/expe ,我希望任何用户都可以在其上创建.txt文件。 我希望任何用户键入这样的内容:

 $ whoami user1 $ export $file_name=my_txt_file $ /opt/expe/create_file.sh $ ls -cal /opt/expe total 12 drwxr-xr-x 2 root root 4096 Jul 29 19:27 . drwxr-xr-x 6 root root 4096 Jul 29 19:14 .. -rwsr-sr-t 1 root root 65 Jul 29 19:29 create_file.sh -rw-r--r-- 1 user1 root 0 Jul 29 19:27 my_txt_file.txt 

我试着用sudoer

 $ whoami user_sudoer $ cat /opt/expe/create_file.sh touch /opt/expe/$file_name.txt chown $USER /opt/expe/$file_name.txt $ chmod a+x /opt/expe/create_file.sh $ chmod a+t /opt/expe/create_file.sh $ chmod a+s /opt/expe/create_file.sh $ chmod a+X /opt/expe/create_file.sh 

然后使用非root用户获得:

 $ whoami user1 $ export $file_name=my_txt_file $ /opt/expe/create_file.sh touch: cannot touch '/opt/expe/prueba_txt.txt': Permission denied 

我可以这样做吗? 我想要一些像postgres SECURITY DEFINER概念。

我对Postgres不熟悉,但我看到至少4个选项:

  1. 使用chmod更改/ opt / expe的权限,以允许所有用户在此目录中创建文件。

  2. 为需要在那里写入的用户创建一个单独的组,并使用chmod更改/ opt / expe组权限,以允许该组在那里写入。

  3. 创建一个单独的组并添加sudoers规则,让他们执行此脚本,如下所示: 用户如何在VeraCrypt中挂载加密文件容器?

  4. 使用标签安全性进行细粒度访问控制。 以下是安全标签的简要说明和一些其他链接: https : //unix.stackexchange.com/questions/53028/what-are-ext4-security-labels

请记住,创建/删除文件的权限是目录的属性,而不是文件本身。