More sudo vs. su

You can 'get root' using sudo or by using su, however, be aware that they handle things a bit differently.

I've still been seeing some debate about which is better: the use of sudo, or simply using root or su.  They both have their place, actually, but the point here is that they work differently.

When you "sudo -s" to get a shell, your environment is inherited from your current user.  So, you'll notice, that when you sudo -s, and type cd ~, you don't go to root's home, but your current user.  Your $PATH stays the same, too.  Something like you'll see in figure 1:

Figure 1 - sudo in action

su -, on the other hand, gives you the environment of the user you're substituting - typically root.  Look at figure 2:

Figure 2 - su in action

Of course, there are ways to have sudo modify your environment, and there are switches that let su leave it alone.  I'm really talking about default cases here, which seem to be used most of the time.

I'm fine with a combination of sudo and su, depending on the environment.  On my local machine, I tend to su up to root and keep a root shell open somewhere - very old school, part of my preferences, and simply seared into my synapses.  However, sudo tackles a certain role that su does not: many admins, or demi-admins responsible for a given machine or network of machines.  Using sudo you are able to grant root (or other) privileges to specific users for specific commands.  However, more than just giving you root, commands are logged per user.  When a single admin user leaves, revoking that single account keeps you protected, rather than needing to change the root password everywhere (although, you most likely do want to change that, and other, passwords).

Of course, you still need to be very careful with the setup of sudo.  Many commands, seemingly innocent, will allow a user a 'trap-door' that still gives them full run of the system.

So, rather than debate su versus sudo, understand that they're complimentary, and have unique strengths and weaknesses.  Use them in the appropriate situation and neither will let you down.