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.

  • Take a look at man sudo.
    – Cyrus
    Mar 8, 2015 at 12:30
  • Take a look at my update.
    – 3bdalla
    Mar 8, 2015 at 12:31

1 Answer 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?

  • Sorry, but, that is done with ?
    – 3bdalla
    Mar 8, 2015 at 14:53
  • edit your sudoers file with visudo and add username ALL = NOPASSWD: /usr/sbin/ifconfig with ifconfig as example
    – Soopernaut
    Mar 8, 2015 at 15:11
  • 2
    Usually 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 8, 2015 at 15:46
  • 1
    Did not think about this, glad you brought it up. Couldn't you just write protect the script to prevent that scenario?
    – Soopernaut
    Mar 8, 2015 at 16:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.