Add user to group which can access network interfaces
This worked for me:
sudo gpasswd -a yourusername netdev
Source
try adding the user to "netdev" group using usermod command instead of useradd command. Note that user must be an existing user. I have done this myself on Ubuntu 16.04 LTS and it works:
sudo usermod -a -G netdev <user>
after this command, check whether user got added by doing:
id <user>
if not added, try restarting/logging out and do above command (id) again
WARNING: do NOT omit '-a' in first command. Be careful
You can permit a user to run specific tool with root
privilege by editing /etc/sudoers
file. For example you can permit a non-root non-sudoer user to run only ifconfig
command, so he/she can't access root privileged things like viewing /etc/shadow
.
So, create a normal user (MYUSER in my example). Don't add it to root
or sudo
groups. Edit /etc/sudoers
with your favorite editor like vim
. Add this line under # User privilege specification
:
MYUSER ALL=(root) NOPASSWD :/sbin/ifconfig *
Then access ifconfig
using sudo
when logged in as MYUSER. For example:
sudo ifconfig eth0 down
Replace ifconfig
in this answer with any tool you want like tcpdump
, tshark
, etc.
Reference is here.