0
我想编写一个设置mercurial存储库的shell脚本,并允许组“ ”开发人员“的所有用户执行此脚本。在使用sudo运行时找到shell脚本
该脚本归用户“hg”所有,并且在运行时工作正常。当我尝试运行它与其他用户 ,使用sudo时,执行暂停与“权限被拒绝”错误,当它试图源另一个文件时出现问题。
有问题的脚本文件:
create_repo.sh create_repo.sh的
#!/bin/bash
source colors.sh
REPOROOT="/srv/repository/mercurial/"
... rest of the script ....
权限和colors.sh:
-rwxr--r-- 1 hg hg 551 2011-01-07 10:20 colors.sh
-rwxr--r-- 1 hg hg 1137 2011-01-07 11:08 create_repo.sh
sudoers的设置:
%developer ALL = (hg) NOPASSWD: /home/hg/scripts/create_repo.sh
我的“ m试图运行:
[email protected]:~$ id
uid=1000(user) gid=1000(user) groups=4(adm),20(dialout),24(cdrom),46(plugdev),105(lpadmin),113(sambashare),116(admin),1000(user),1001(developer)
[email protected]:~$ sudo -l
Matching Defaults entries for user on this host:
env_reset
User user may run the following commands on this host:
(ALL) ALL
(hg) NOPASSWD: /home/hg/scripts/create_repo.sh
[email protected]:~$ sudo -u hg /home/hg/scripts/create_repo.sh
/home/hg/scripts/create_repo.sh: line 3: colors.sh: Permission denied
所以脚本被执行,但在试图包含其他脚本时暂停。
我也尝试使用:
用户@ NEBU:〜$ sudo的-u HG /斌/庆典/home/hg/scripts/create_repo.sh
可以得到相同的结果。
如果可以通过sudo使用其他用户运行脚本,那么包含另一个shell脚本的正确方法是什么?
您的权限看起来不对。每个有权读取的人都应该可执行脚本。如果一个脚本只是来源并且从不执行,它不应该是可执行的:`chmod a + x create_repo.sh; chmod a-x colors.sh` – 2011-01-12 16:23:09
原因''create_repo.sh''没有''a + x'',因为它打算使用''sudo -u hg''运行。 colors.sh没有为其他人设置的执行位,不需要删除它。 – 2011-01-15 21:55:16