【问题标题】:permission denied in running script运行脚本中的权限被拒绝
【发布时间】:2014-02-25 19:06:53
【问题描述】:

我正在运行一个脚本,但有一个不寻常的警告: 这就是我的控制台中发生的事情

#whoami
root
#ls -l test.sh
-rwxr-xr-x. 1 root root 1894 Feb  2 01:58 test.sh*
#./test.sh
-bash: ./test.sh: Permission denied

编辑: 我的脚本:

#!/bin/bash
while read pass port user ip file; do
  echo "startt------------------------------------" $ip
  ping $ip -c 4
  if [ $? -eq 0 ]; then
    echo $ip ok...
  else
    echo $ip failed...
  fi
  echo "finish------------------------------------" $ip
done <<____HERE
pass  22  root  1.1.1.1  test.txt
____HERE

有什么想法吗? 谢谢你

【问题讨论】:

  • 取决于 test.sh 的作用(例如是kill -9 1?还是sudo tomcat rm -rf /?但大多数情况下,这个问题属于SuperUser,因为它与编程无关。
  • 同意@PaulHicks。程序似乎正在执行,脚本中存在权限错误
  • 真的没有..这是简单的脚本..脚本中没有发生异常
  • 在大多数 linux 系统上,您实际上可以在文件名中添加星号。从您的ls 输出来看,该文件的名称中似乎有一个 *。所以试着用./"test.sh*"运行它
  • 这也有道理,能发一下脚本吗? @PaulHicks,只需再次按下否决票。

标签: linux bash shell centos


【解决方案1】:

我在 /tmp 目录中运行脚本 如您所见, ls 的结果是:

-rwxr-xr-x. 1 root root 1894 Feb  2 01:58 test.sh*

权限后有.,表示 SELinux 安全上下文适用于该文件。所以我将 test.sh 复制到其他目录中...

问题解决了

ls -l /
drwxrwxrwt.   8 root root  1024 Feb  2 07:44 tmp/

我所在的目录可能不适合存放可执行文件

这些也可能有效:

setenforce 0 | reboot

echo 0 > /selinux/enforce | reboot

或者:

putting SELINUX=disabled in /etc/selinux/config and reboot (making sure to comment out anything in that file enabling selinux)

SELINUX 状态:sestatus

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 2015-11-15
    • 1970-01-01
    • 2018-12-25
    相关资源
    最近更新 更多