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.

I'd like to know if there is any reason why I should use sudo instead of su, taking into account that I am the owner and sole user of my machine (and hence have root access whenever I want). Also, in case there is a good reason to prefer sudo, I want to know what privileges should I give myself.


EDIT: I have just found a very nice reference for sudo. If anyone is interested it is here.

share|improve this question
    
As the only user sudo, through /etc/sudoers, gives you quite a lot of fine grained control over when you require passwordless elevated privileges. This mitigates some of the risk around overuse of said elevated privileges. You also use your own environment and settings, not root's. –  jasonwryan Dec 25 '13 at 3:23
    
I'm afraid I don't understand your answer. I get sudo is usefull in a big workspace to restrict what each 'employee' is able to do without asking the administrator. But in my case, since I also own the root password, how can I benefit from it? –  Tom Reich Dec 25 '13 at 3:43
1  
It allows you to methodically determine what comands you will not require elevated privileges for; meaning that you are less likely to habitually switch to root and inadvertently break something. Essentially, it is helpful to tailor your setup to meet your needs around privileges, rather than the one-size-fits-all approach that root entails. Ultimately, though, it comes down to personal preference... –  jasonwryan Dec 25 '13 at 4:08
    
You can decide what environment you want when you run one-off commands more easily than with su. –  Bandrami Dec 25 '13 at 4:08
    

1 Answer 1

up vote 3 down vote accepted

Yes, segregating root privileges protects you from yourself. If you log in as an unprivileged user, then the worst you can do (without sudo) is destroy your own userspace. Root can potentially destroy everything on the system, any connected drives, and any network connected read-write mounts with a simple rm -fr /.

Also, using sudo rather than su decreases the chances you will su up to root, do a thing, and then leave the superuser shell open.

share|improve this answer
    
So that is what they mean when they say sudo operates on a per-command-basis: using sudo you just run the specific command as root and you're done; you never get to be root (i.e. your prompt never changes from $ to #). Is this right? –  Tom Reich Dec 25 '13 at 4:07
    
That's exactly correct, notwithstanding sudo -s. –  DopeGhoti Dec 25 '13 at 4:10
    
Okay, so it reduces the 'temptation' to become superuser and have unlimited power. In my case, since I am a beginner, I could configure sudo to let me run all commands but asking me for authentication each time I invoke it, right? –  Tom Reich Dec 25 '13 at 4:15
    
The defaiult behavior of sudo is to require the user to authenticate the first time it is used, or if a certain amount of time has passes since it was last used. It is possible to change it to always require a password. This can be done in /etc/sudoers by changing that timeout to zero. Be sure to edit this file using visudo and not directly, as if you mess up when editing directly, you cah lock yourself out entirely with a broken sudoers. –  DopeGhoti Dec 25 '13 at 4:18
2  
Also, the use of sudo increases the likelihood that you remain the only user of your computer. –  Tim Kennedy Dec 25 '13 at 5:02

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.