0

I am trying to get rid of password when changing proxy with networksetup. I changed permissions to read and write of /private/etc folder and propagated change to subfolders.

I tried this:

sudo chmod u+s /usr/sbin/networksetup

and it says:

    `/etc/sudoers is world writable`
no valid sudoers sources found, quitting

Changed permission back to readonly, now it says

Unable to change file mode on /usr/sbin/networksetup: Operation not permitted

I also tried with visudo -f /etc/sudoers, but I don't know how to edit file from here. Can you help me out?

EDIT: after running visudo -f/etc/sudoers I get this error. Should I delete the swap file? No additional program is editing sudoers folder

E325: ATTENTION
Found a swap file by the name "/etc/.sudoers.tmp.swp"
          owned by: mainuser   dated: Sun May  1 16:28:25 2016
         file name: /private/etc/sudoers.tmp
          modified: YES
         user name: mainuser   host name: Mains-MacBook-Pro.local
        process ID: 39284
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
-- More --   dated: Sun May  1 16:23:40 2016

(1) Another program may be editing the same file.
    If this is the case, be careful not to end up with two
    different instances of the same file when making changes.
    Quit, or continue with caution.

(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /etc/sudoers.tmp"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/etc/.sudoers.tmp.swp"
    to avoid this message.

Swap file "/etc/.sudoers.tmp.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
-- More --

EDIT: For future reference, if you edit file manually, make sure to do this: https://discussions.apple.com/thread/7262040?start=0&tstart=0

1

Open Terminal and enter sudo visudo to modify the file /etc/sudoers.

Change the part:

## User privilege specification
##
root ALL=(ALL) ALL
%admin  ALL=(ALL) ALL

to

## User privilege specification
##
root ALL=(ALL) ALL
%admin  ALL=(ALL) ALL
your_username ALL=(ALL) NOPASSWD: /usr/sbin/networksetup

and save the file.

If you don't know vi: after entering sudo visudo you have to change to insert mode by hitting i. Enter the additional line as indicated above. To leave insert mode hit esc. Then enter :wq and the Enter key to write the modified file to disk and quit vi.

Using sudo networksetup ... shouldn't require a password anymore.

  • If I open sudoers file in textEdit I indeed see what what you mean. Is it okay to just edit the file manually? (there are some warnings at the top, when I open it). Upon using visudo command I end up with the code above. Should I delete the swap? – sanjihan May 1 '16 at 15:26
  • @sanjihan You should first repair/fix the permissions for etc and all items within (files and folders) – klanomath May 1 '16 at 16:20
1

You cannot change the permissions on /usr/sbin/networksetup on a Mac running El Capitan with default settings.

In order to that you need to disable System Integrity Protection. Do this by rebooting the Mac, holding down Command + R to enter Recovery mode. In Recovery mode click the Utilities menu and select Terminal. In the Terminal run the following command:

csrutil disable ; reboot

Your Mac will reboot into the ordinary OS X system, where it is now possible to change the permissions on /usr/sbin/networksetup.

After you're done with that, follow the same steps to run this command in Recovery mode:

csrutil enable ; reboot

Your system will reboot and System Integrity Protection will be enabled again.

  • Though this may solve the file permissions mod problem this is no proper or recommended way to solve the main question. – klanomath May 1 '16 at 15:01
  • @klanomath For anyone running El Capitan or later it seems to me that this is the only way to accomplish what the OP was ultimately trying to achieve. Unless I'm mistaken, editing the sudoers file without first temporarily disabling SIP is an exercise in futility. – I0_ol May 1 '17 at 17:39

You must log in to answer this question.

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