I want to create a shortcut that opens terminal and run sudo nethogs
command without asking me for root permission.
-
Where is your problem? The shortcut or the sudo part? – PerlDuck May 26 '18 at 13:02
-
sudo part . I want to start the program in terminal without asking me for password and i don't get popup to fill password, it is asked in terminal. – Amanpreet Singh May 30 '18 at 09:34
1 Answers
There are two ways on how to solve this problem:
Grant nethogs
the required capabilities
I think the easiest and safest way to do this is to make nethogs
able to run without root permissions. You can do this by giving it the permissions it is currently temporarily acquiring as root every time you launch it. You can do that with the following command:
sudo setcap "cap_net_admin,cap_net_raw=ep" /usr/sbin/nethogs
Once you have given nethogs
these capabilities, it should be able to capture your network traffic without root permissions and you should therefore be able to use it with a shortcut, without having to fill out any credentials.
Edit /etc/sudoers
However, a more general way of solving this sort of problems can be found here How do I run specific sudo commands without a password? Which basically tells you how to safely add nethogs
or any other command to /etc/sudoers
to be able to execute it without manually having to type in a password.