I am running Yosemite 10.10.5 and I have a shell script which I want to use to toggle whether my wifi connections run through tor or not. This uses the networksetup a couple of times and so asks for my password each time I run or cancel it.

Is there a way to make a shell script run without requiring my password each time?


  • You can edit the sudoers file to give your user access to networksetup without requiring a password. Is networksetup the only command requiring sudo?
    – nohillside
    Commented Sep 21, 2015 at 5:51
  • 1
    yep. would you mind elaborating on what and how to edit? Commented Sep 21, 2015 at 5:52
  • Need to get in front of a Mac first to make sure I get it right, stay tuned :-)
    – nohillside
    Commented Sep 21, 2015 at 6:02

1 Answer 1


You can add a rule to the /etc/sudoers file to give your user access rights to networksetup without a password.

  1. Note the user name of the user account which should be allowed to run the command (you can get the user name by running whoami in Terminal)
  2. Log in as an admin user
  3. Open Terminal
  4. VISUAL=nano sudo visudo - opens the sudoers file in a kind of friendly editor
  5. Jump to the bottom
  6. Add

    USERID-FROM-STEP1 ALL = NOPASSWD: /usr/sbin/networksetup

    followed by an empty line(!)

  7. Save and quit

You should now be able to run networksetup as the user from step 1 without a password prompt by simply entering sudo networksetup.

  • what if the user is just me? would it be the name of my home directory then? Commented Sep 21, 2015 at 7:00
  • @river_jones To get your proper userid just enter whoami in the Terminal. Usually (but not necessarily since you may have renamed your user folder or your user previously) it's the same name as your home folder in /Users.
    – klanomath
    Commented Sep 21, 2015 at 8:03
  • On an unrelated note, I was just curious and replaced nano with subl (I use sublime for development) and this just opened a new blank file (like touch). Why is it that nano opens the "correct" /etc/subdoers.tmp` but subl doesn't? Commented Sep 21, 2015 at 14:15
  • Btw, I didn't realize that as an admin I could just add sudo to my networksetup calls and it's sufficient to suppress password confirmation. But this is useful for allowing the same for non-admin's. Thanks for your time and help! Commented Sep 21, 2015 at 14:37

You must log in to answer this question.

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