2

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 .

gladiator
  • 123
  • 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 06 '23 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 06 '23 at 12:51
  • Then set two different Locations in Network & swap between them. – Tetsujin Jul 06 '23 at 12:52
  • How to do that ? , this value is on hardware level .

    https://www.dwthacker.com/finding-and-setting-mtu-on-mac

    – gladiator Jul 06 '23 at 12:54
  • https://support.apple.com/en-us/HT202480 – Tetsujin Jul 06 '23 at 12:55
  • I can get sudo for one time but that password expires after specific period so , I just want something where I don't need to that password again and again – gladiator Jul 06 '23 at 12:55
  • 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 06 '23 at 12:59
  • seems I am on monterey and this applies to ventura only , upgrading OS not possible as of now – gladiator Jul 06 '23 at 12:59
  • got it let me ask them to open network panel for me . if they can – gladiator Jul 06 '23 at 13:00
  • I give up. You stopped reading before you got halfway down the page. If you're not going to try, neither am I. – Tetsujin Jul 06 '23 at 13:01
  • I read that later on , I got it now seems that too is locked on my machine , I will ask admin to open network location and see it that works – gladiator Jul 06 '23 at 13:03
  • @Tetsujin seems MTU can't be managed by location , changing mtu on one location changes for the other as well – gladiator Jul 10 '23 at 08:32
  • The settings are completely independent. Changing one Location does not affect the other at all. That's the whole point, that you can completely re-config your Network for one Location without breaking your other Locations. See pics Automatic and a testMTU – Tetsujin Jul 10 '23 at 08:48
  • Does it works for wifi as well for you , for me changing on one location changes elsewhere too Can't put pics due to upload restrictions – gladiator Jul 10 '23 at 09:09
  • Yup, works just the same. It doesn't show up that it's got the correct numbers until you activate the location with the Apply button. – Tetsujin Jul 10 '23 at 09:17
  • 1
    Working for me thanks a lot . – gladiator Jul 10 '23 at 10:04
  • Glad to hear it. I threw in a quick answer ;)) – Tetsujin Jul 10 '23 at 10:09

2 Answers2

4

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.

Allan
  • 101,432
3

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.

Tetsujin
  • 115,663