i would like to allow a user without root permission to enable/disable a network interface from the command line, such as:

ip link set ens18 down

(ubuntu 18.04 with netplan)

i would appreciate any input or help cheers!


probably the best way to do this is via proper configuration of sudo. You can specify exact commands that can be run, and you can (if you choose) make it not required to enter a password

You can either use /etc/sudoers or /etc/sudoers.d/network_interface

With content similar to

user1 ALL=(ALL) /usr/bin/ip link set ens18 down

See here: https://www.sudo.ws/man/1.8.15/sudoers.man.html

All the way down at the bottom is an EXAMPLES section, if you don't want to read the whole thing

  • Perfect solution for me. i added two lines like the one you suggested (the second with "up" at the end) and i will do this for a whole group instead of a user. Thank you! by the way: i needed to restart the machine so that the effect takes place. is this really needed? when i try to restart the service it says that the unit sudo.service is masked... – gian Dec 9 '19 at 8:40
  • It is not normally required with a standard linux/unix setup. It's a little strange that a reboot was required – stratus Dec 9 '19 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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