7

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?

  • 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
4

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.

|improve this answer|||||
1

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 ####
|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
1

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
else
    sudo NewNetConfig -setsocksfirewallproxystate Wi-Fi off
    say off
fi

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

|improve this answer|||||
0

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: http://www.linuxnix.com/2011/12/suid-set-suid-linuxunix.html

|improve this answer|||||

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