Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a few network scripts that I used under OS X Lion that automatically created a ssh connection and then changed network configuration on my local machine to run traffic through the ssh tunnel. I changed the network configuration using these shell commands:

networksetup -setsocksfirewallproxy "Wi-Fi" localhost ####

networksetup -setsocksfirewallproxystate "Wi-Fi" on

Now, under Mountain Lion, it asks for a password for both every time I run the script, which is very annoying. Is there a way to have it remember the password, or bypass it, or just put it in the first time and have it remember?

share|improve this question
Also, I'm looking for a "non-hacked" solution. For example, I would rather NOT write an applescript to type in the password for me. – SudoKill Jul 27 '12 at 23:23

Make sure that your scripts have the right permissions and owner. It should be root:wheel like this(wifi is the script name):

lion:~/Downloads napcae$ ls /usr/local/bin/
-rwxr-xr-x  1 root      wheel       739 25 Nov 18:35 wifi

You can achieve this by typing

lion:~/Downloads napcae$ sudo chown root:wheel wifi

Now you can sudo your commands in the script, i.e.

sudo networksetup -setnetworkserviceenabled "Huawei Modem" on;

The Terminal/Finder should stop asking for the password. I hope this helps.

share|improve this answer
up vote 1 down vote accepted

not sure if this is the right way to do it from a security viewpoint, but it works:

1) Copy networksetup in /usr/sbin/ to another file (this way, all the other services using it will continue to require the password when run):

sudo cp /usr/sbin/networksetup /usr/sbin/NewNetConfig

2) Add this line in your sudoers file to skip password when calling NewNetConfig:

username   ALL=NOPASSWD: /usr/sbin/NewNetConfig

3) Restart. Then use this to change your network configuration and it shouldn't ask for a password:

sudo NewNetConfig -setsocksfirewallproxy "Wi-Fi" localhost ####
share|improve this answer
Just to be clear and thorough, to perform step 2 you need to $ sudo visudo – cfx Jul 8 '14 at 1:12

I had the same problem, instead I Used a service to switch the proxy state by pressing a shortcut key.

After you've done coping networksetup to NewNetConfig and editing /etc/sudoers, Create a new Service in Automator named "ChangeWiFiProxy". Add a Shell Script and add this script:

STATUS=`NewNetConfig -getsocksfirewallproxy Wi-Fi | grep -c 'Enabled: Y'`
if   [ "$STATUS" == "0" ] ; then
    sudo NewNetConfig -setsocksfirewallproxystate Wi-Fi on
say on
    sudo NewNetConfig -setsocksfirewallproxystate Wi-Fi off
    say off

Then assign it a shortcut like Cmd + Option + ";" in "System Prefrences > Keyboard > Keyborad Shortcuts > Services".

share|improve this answer

You can set permission suid to /usr/sbin/networksetup and then networksetup will run with root permission, so you don't need to input password anymore.

sudo chmod u+s /usr/sbin/networksetup

About suid:

share|improve this answer

protected by bwDraco 3 hours ago

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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