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.

  • 2
    You could trap on error, but you will need a way to know if sudo will solve the problem, or else you will get a lot of sudo-ing when it should not. – ctrl-alt-delor May 31 '15 at 11:18
  • You say that you don't care if you have to type in the password more. But do you care if you never are asked to type in the password? – ctrl-alt-delor May 31 '15 at 11:19
  • Would running any command under the uid of root an acceptable risk? In this case you don't need a sophisticated kernel rewrite: /usr/bin/sudo /bin/bash would be an easy solution. – daniel Azuelos Jun 1 '15 at 21:22
  • Fedora 22 did this for me immediately after installing. I would enter dnf install something without sudo and it would ask me for my password (actually I can just enter something and it asks whether to install it.). For some reason, it stopped working though. – jdm Aug 13 '15 at 5:41

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.


A simple stopgap would be to identify the commands that you run that (always) require privilege, and alias them:

alias dnf="sudo dnf"
  ⋮     ⋮     ⋮

I would advise against doing this for every command that you use; especially not ones that can do harm (e.g., cp, mv, and rm).  In fact, I, personally, wouldn't do it for things like ls; if I'm not running as root, I think it's right and proper that ls -l /root should fail.  A case could be made for doing it for find, but then remember that any program that you run with -exec inherits the superuser privileges that find is running with.

  • Good answer: 80% of the time you will be running just 20% of all the commands that you ever use. Therefore there should not be many commands that you need to alias. – ctrl-alt-delor May 31 '15 at 11:14

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.