10

Is there any difference between using sudo and using su -c? There are situations where one should be used but not the other?

I was previously using Ubuntu where sudo appears to be ubiquitous but now I'm giving Fedora 15 a try and the idiom su -c appears frequently when I'm trying to learn how to do a few things, although I still see sudo being used now and then.

14

The difference between sudo and su is how they perform authentication:

  • su prompts for the target user's password.
  • sudo checks whether the source user is authorized to run the command (the authorization is specified in /etc/sudoers). Depending on the configuration, it might prompt for the source user's password, both to mitigate the risk of an unattended console and to alert the user that privilege escalation is going on.

Once authorized, the effect is the same: run a command as root (or, if specified on the command line, as some other user).

There are further minor differences: they don't take the same options, and they don't set the environment for the command they run in exactly the same way. But for common usage, they're the same.

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.