2

I have created an alias for myuser that is

alias up='sudo apt update && sudo apt -y upgrade && sudo apt -y autoremove'

It is stored in the user's .bashrc file. I have tried to modify sudoers file inserting the following line at the end of it:

myuser ALL=(ALL) NOPASSWD: up

visudo gives a syntax error however. How can I make my alias run without the password for root?

2 Answers 2

2

If you want to run all sudo commands without a password you can use this.

myuser ALL=(ALL) NOPASSWD:ALL

If you want to limit it to only a few commands you can use this.

myuser ALL=(ALL) NOPASSWD: /usr/bin/apt,/usr/bin/command
1

I guess it's not working because :up is an alias, not a path to a file. Aliases are caught and expanded by the shell before being executed.

To get the behavior you want you'll have to use :

myuser ALL=(ALL) NOPASSWD: /usr/bin/apt

(Double check that it's the correct route for APT, I don't have any apt based distro handy right now).

But what you are trying to do is a disaster waiting to happen, at least if you don't ommit that " sudo apt -y autoremove". Autoremove should be used with caution and reviewing what's planning to remove, as it can remove essential packages sometimes and really mess with your system (I learned the hard way)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .