Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
1  
    
See also this question –  Vorac Aug 11 '13 at 17:42
add comment

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.