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?


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)


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


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

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.