I want to run below command

 networksetup -setMTU en0 1280

but this requires admin credentials

   networksetup -setMTU en0 1280 
** Error: Command requires admin privileges.

I want to create a script that run this command with sudo (the credentials keeps changing so can't have them will me ) and then run it with my user which has no admin/sudo rights.

So is it possible to create a script that run as admin (no password inside it ) and non admin user can run it and perform the specific task.

Most probable scenario is that they won't provide me sudo rights so need one time activity on admin team end and then use that solution .

Note- this command need to be run in specific condition and upon wifi restart it need to be run again .

  • If you're not in sudoers, you're not getting in. Why can't the user just set it in the Network setup page? Why does it need re-setting each time?
    – Tetsujin
    Jul 6 at 12:50
  • when using office wifi I need different value for MTU and when using home mobile hotspot different value is needed.
    – gladiator
    Jul 6 at 12:51
  • Then set two different Locations in Network & swap between them.
    – Tetsujin
    Jul 6 at 12:52
  • 3
    You're making an XY Problem out of this. You don't need admin to change MTU from the control panel & you don't need admin to change Location, unless the owner of the Mac has locked it down with MDM. If they have, tell them about this issue & see if they'll unlock the Network panel for you.
    – Tetsujin
    Jul 6 at 12:59
  • 1
    Working for me thanks a lot .
    – gladiator
    Jul 10 at 10:04

2 Answers 2


With the aid of a little bickering in comments ;) the simplest solution to this, which doesn't require admin permissions, sudo or any Terminal interaction at all is to set up two Locations in Network, each set to a different MTU.

enter image description here

This then enables two entirely different configurations to be set up; enabling switching between the two at each Location.

enter image description here

enter image description here

Note: The settings may show incorrect greyed-out information until each Location is actually activated, using the Apply button.


Modify Your sudoers file.

What you can do is modify your sudoers file so that you grant "no password" access to the command in question only.

username ALL = (ALL) ALL
username ALL = (root) NOPASSWD: /path/to/foo/bar/command

With this method, you leave your system security intact and allow for the use of sudo with no password for this one particular command.

You must log in to answer this question.

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