Terminal - don't require password for shell script to run
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?
Thanks!
You can add a rule to the /etc/sudoers
file to give your user access rights to networksetup
without a password.
- 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) - Log in as an admin user
- Open Terminal
-
VISUAL=nano sudo visudo
- opens the sudoers file in a kind of friendly editor - Jump to the bottom
-
Add
USERID-FROM-STEP1 ALL = NOPASSWD: /usr/sbin/networksetup
followed by an empty line(!)
- 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
.