Difference between using su

A question for all the linux geeks to answer?
What is the difference between “su root” and “su - root”?
What is differenc between “update-grub” and “/usr/sbin/update-grub”?
The reason I ask is because I had to use “/usr/sbin/grub-install /dev/sda” to get Debian 12 to install grub. It took some thinking but I finally found a way.

Some recent distros (eg Debian 12) have decided that
$PATH for root should not include /sbin and /usr/sbin.
That forces you to type the full path for all adminstrative commands.
I you dont like it, the fix is to add /sbin and /usr/sbin and /usr/local/sbin to root’s PATH
it is supposed to be a security measure.

su - starts the root shell as a login shell.

2 Likes

How do I do that?

su” and "su root’ are the same thing - “root” bit is redundant - you only specify the user if it’s not root…

su -” and “su - root” are also the same thing - i.e. “root” is redundant. As @nevj mentioned “su -” loads root’s shell and profile…

The only time I might use “su” and specify a user - might be e.g. I need to log in as an application owner, e.g. “oracle” - I’d probably “sudo -i” to get root’s profile and god privileges, then “su - oracle” to become “oracle” user when I don’t know that user’s password - and maybe that’s a good thing (and DO NOT CHANGE IT!).

I hardly ever user “su” - mostly just “sudo -i”… See a lot of people (including colleagues with years of UNIX under the belt) doing “sudo su -” - when “sudo -i” works equally well and is quicker to type :smiley:

Note also - many distro’s don’t have a password set on the root user account - e.g. most Ubuntu based distros (e.g. Pop!_OS) - there is no password for root by default, so you can keep typing “su -” and never get in because the password hasn’t been set.

4 Likes

PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin

put that line in root’s .bashrc or .profile or .bashrc_profile

4 Likes

Thanks to the both of you for a very well put explanation!!! Cannot see the reason why Debian felt the need for a long path, just to install and update grub, but I guess this is all in the scheme of things, too make Linux so great for the user.

1 Like

Guilty. :raised_hand_with_fingers_splayed:

1 Like