1

I have a simple shutdown script which i want to run as root

shutdown -h +30;
echo "succesfull";

I have followed these answer1,2 to make my script root.

first I run this command

sudo chown root.root $HOME/test/test.sh
sudo chmod 4755 $HOME/test/test.sh

and then made changes in sudoers

sudo visudo

added this command after this line %sudo ALL=(ALL:ALL) ALL

eka ALL=(ALL) NOPASSWD: $HOME/test/test.sh

But when i executed my script its showing this error

shutdown: Need to be root
succesfull
5
  • chmod 4755 - I assume you meant to make a setuid script? Scripts can't be made setuid.
    – muru
    Commented May 22, 2015 at 9:07
  • @muru I was following the answer 1
    – Eka
    Commented May 22, 2015 at 9:12
  • That user is mistaken. setuid doesn't work on scripts. Period.
    – muru
    Commented May 22, 2015 at 9:17
  • @muru thanks for the info.. but how to revert back to normal executable script whether this code be enough sudo chmod +x $HOME/test/test.sh
    – Eka
    Commented May 22, 2015 at 9:19
  • 2
    You need to do chmod u-s, but as I said, it doesn't matter - setuid doesn't affect scripts.
    – muru
    Commented May 22, 2015 at 9:20

1 Answer 1

4

Don't use setuid shell scripts, the SUID bit is not honored on shell scripts anyway on current systems. Use sudo instead, as you attempted anyway:

eka   ALL=NOPASSWD: /home/eka/test/test.sh

And then:

eka$ sudo ~/test/test.sh

With that, test.sh will be executed as "root". No need to use setuid here.

2

You must log in to answer this question.

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