I have been following this iptables guide online and came across a problem where I tried to give myself execute permissions to a file that is owned by root and stored in root's home folder. Here is the online document as a reference:
iptables guide
It says:
Make sure you can execute the script
$ chmod +x /root/fw.stop
And then:
You can run the script
$ /root/fw.stop
When I entered the command "chmod +x /root/fw.stop", I received an error "chmod: cannot access `/root/fw.stop': Permission denied".
Obviously, if I want to run the script, I can do so by simply typing "sudo /root/fw.stop", but I'm trying to learn; did the writer of the guide just make a mistake with his syntax that he listed, or am I doing something wrong?
I tried "sudo bash -c "chmod +x /root/fw.stop"" and then tried to run the script again as myself with the command "/root/fw.stop" but I received the error "bash: /root/fw.stop: Permission denied".
Best Answer
The author made a number of mistakes.
This is what you should be doing:
As root (sudo -s) create the file /root/fw.stop:
Then enter the following script (note the change in the first line):
Then you can chmod it (still as root):
Then you can run it (yes, still as root):
If you want to run it as anyone other than root then you should use sudo (
sudo /root/fw.stop
). The setuid bit is possible but a serious security hole as it would allow anyone to run the script.