Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 以其他用户身份运行脚本-为什么权限被拒绝?_Bash_Permissions_File Permissions - Fatal编程技术网

Bash 以其他用户身份运行脚本-为什么权限被拒绝?

Bash 以其他用户身份运行脚本-为什么权限被拒绝?,bash,permissions,file-permissions,Bash,Permissions,File Permissions,我正在以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: #

我正在以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

权限被拒绝可能发生在以下情况:

  • 该脚本没有调用它的用户的执行权限
  • 哈希爆炸(
    #!
    )后的路径不正确或未指向可执行文件(或者用户没有执行此脚本的权限)
  • 用户没有指向脚本的所有文件夹的执行权限
  • 在代码中,您将chmod 777设置为
    testuser.sh
    ,但随后尝试执行
    testuserscript.sh

    我不希望
    su
    更改文件夹,但可以尝试绝对路径。还要检查新创建的已使用的默认shell。要避免所有这些问题(以及其他一些问题),请尝试:


    您可以稍后使用变量来定义所有脚本都在哪个文件夹中。

    您可以尝试
    sudo-u testuser命令
    是否在所有指向
    testuserscript.sh
    的目录上都有+x?@thatotherguy是的。我一直尝试使用chmod 777,直到/tmp/。也不走运。@otherguy这两个脚本都在/tmpIs
    /tmp
    中,并用noexec挂载?
    sudo -u testuser bash /tmp/testuserscript.sh