Fedora – Prompt for sudo password rather than give access error

fedorarootsudo

Can I configure Fedora 22 so anything needing root privileges asks for a password, rather than giving an error, and needing me to re-run with sudo? I wouldn't even mind having to type my password every time, without the few minute (or whatever it is) timer that it remembers the password for.

i.e. Instead of:

$ dnf history
You don't have access to the history DB.

It would:

$ dnf history
[sudo] password for <username>:

I think some of the gui apps do that, like the gui yum frontend back when I had that installed.

I'm thinking not… That it would be up to each app to implement this. But, I'm hoping it might instead be that apps say root privilege is needed, and there might be some way for the kernel (or wherever else) to remain in a blocking input stage (for the password) before returning whether the user has access.

Best Answer

You could use the python script thefuck available on github. This script is designed to correct the last command you ran incorrectly for a few use cases and forgetting to use sudo is one of them.

From their examples:

➜ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

➜ fuck
sudo apt-get install vim
[sudo] password for nvbn:
Reading package lists... Done

This behavior is from the sudo rule you can enable:

sudo – prepends sudo to previous command if it failed because of permissions;

If this doesn't work out of the box for dnf it should be straightforward to create a custom rule to do so.

Related Question