I am sure this question has been asked before but I can't find an answer.
I would like to configure Linux so that when I enter specific commands (e.g. apt-get
), I wouldn't have to enter password as I have to right now.
How can I do this?
I am sure this question has been asked before but I can't find an answer.
I would like to configure Linux so that when I enter specific commands (e.g. apt-get
), I wouldn't have to enter password as I have to right now.
How can I do this?
You can't configure Linux not to require sudo. Some commands need to be executed as root; if you want to trigger them from an unprivileged account, sudo or some other privilege escalation mechanism is necessary.
You can configure sudo not to require a password for specific commands, by adding a sudoers
rule with the NOPASSWD:
tag. Note that NOPASSWD rules must come after non-NOPASSWD rules that match the same command.
%admin: ALL = (ALL:ALL) ALL
%admin: ALL = (root) NOPASSWD: apt-get
Note that allowing apt-get
is as dangerous as allowing any command, since the caller could pass options that cause apt-get
to download packages from sources that they specify, that cause it to invoke hooks that they specify, etc.
If you feel you're seeing too many prompts, you can make sudo prompt you less often. Turn off the tty_tickets
option so that you can authenticate once for the whole session instead of once per terminal. By default, the timeout after which you need to enter your password again is 15 minutes.
Use visudo
to configure your /etc/sudoers file. You probably want something like this:
ALL ALL=NOPASSWD: /usr/bin/apt-get
See man sudoers
for details.
If you really want to avoid sudo altogether you can set the sticky bit like this:
chmod u+s /usr/bin/apt-get
Whether this works depends a bit on the application. This way the command runs as effective user root, but the command itself is able to detect that fact and refuse to work, if it decides so.
apt-get
withoutsudo
or just that when you do run it withsudo
you don't have to enter a password? – Chris Davidson Dec 30 '14 at 16:32sudo
. – syntagma Dec 30 '14 at 16:33