1

I am running a script but there is an unusual warning: This is what happened in my console

#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

Edit: my script:

#!/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

any idea? thank you

1 Answer 1

3

I am running the script in /tmp directory as you see the result of ls is:

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

there is . after permissions which indicates that an SELinux security context applies to that file. so I copied test.sh in a directory else...

the problem was solved

I was in a directory where it might be a bad idea for executables to reside

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

These may work as well:

setenforce 0 | reboot

OR

echo 0 > /selinux/enforce | reboot

OR:

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

SELINUX status: sestatus

3
  • 1
    Disabling SElinux just to run a script might not be a good idea...
    – Wilf
    Feb 2, 2014 at 8:32
  • Copying a file is like creating a new one, so there are a couple of options. 1) Try restorecon /tmp/test.sh after you copied it. That could work if the file context is generic enough. 2) Run ls -lZ on the original test.sh, get the context, and then set that context with 'chcon' if the first option didn't work.
    – Andrew
    Feb 4, 2015 at 22:43
  • "I was in a directory where it might be a bad idea for executables to reside"
    – Wastrel
    Feb 17, 2018 at 19:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .