Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

4 Answers

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
add comment

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".

share|improve this answer
add comment
up vote 0 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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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