I created a simple bash script which contains the command ifconfig
. In general I want to execute such a privileged script to run as non-root user. I have tried hown root:users ./path/to/script.sh
followed by chmod 4550 ./Desktop/dhcp_client.sh
I tried even 4755. I want to use bash scripts to include some privileged commands then I must run the script that contains them as non-root. Then I must invoke these scripts from an application which is run as non-root.
Asked
Active
Viewed 5,042 times
1

3bdalla
- 441
1 Answers
1
Not exactly a pretty solution, but shouldn't it work when you run commands that require root privileges with sudo inside the script and add a nopasswd rule for them?

Soopernaut
- 36
-
-
edit your sudoers file with visudo and add username ALL = NOPASSWD: /usr/sbin/ifconfig with ifconfig as example – Soopernaut Mar 08 '15 at 15:11
-
2Usually that is a horrid horrid answer. Your allowing anything in script.sh to be run as root. It's not -so- bad when it's a compiled application, but when it's shell script (as in the question) you can just edit it with a text editor and run any privileged command you want. If your going to go this route make sure to allow sudo to the individual commands and not the shell script it's self. – coteyr Mar 08 '15 at 15:46
-
1Did not think about this, glad you brought it up. Couldn't you just write protect the script to prevent that scenario? – Soopernaut Mar 08 '15 at 16:00
man sudo
. – Cyrus Mar 08 '15 at 12:30