【发布时间】:2014-08-14 22:59:57
【问题描述】:
我正在以 root 身份运行一个脚本,该脚本使用 useradd 和 passwd 创建一个用户。然后在运行一些需要以新创建的用户身份运行的其他命令之前进行一些检查/安装。
所以我有创建用户的主脚本:
main.sh:
#!/bin/bash
useradd testuser
passwd testuser
yum -y install git
chmod 777 testuser.sh
su testuser -c ./testuserscript.sh
testuserscript.sh:
#!/bin/bash
git clone git://github.com/schacon/grit.git
当我运行 ./main.sh 时:出现以下错误:
bash: ./testuserscript.sh: Permission denied
当我这样做时,我会得到以下信息:
-rwxrwxrwx. 1 root root 728 Jun 24 11:02 testuserscript.sh
我是否运行了错误的命令来运行testscript 作为testuser?
【问题讨论】:
-
你可以试试
sudo -u testuser command -
你在
testuserscript.sh之前的所有目录上都有+x吗? -
@thatotherguy 是的。我尝试使用 chmod 777 一直到 /tmp/。也没有运气。
-
@thatotherguy 两个脚本都在 /tmp
-
/tmp是否安装了 noexec?
标签: bash permissions file-permissions