After a number of recommendations over time to “su -” instead of “su” to an elevated console,
I took a few moments to take a look at this, wondering if others see anything else I’m not covering…
Note that in this case, we are <not> talking about using “su -” to switch to another User(and is different than sudo which grants specified special permissions for a single command only), eg
su - Jane_Doe
We are only considering the use of su and su - for the purposes of persistently elevating permissions to the Super User role by not specifying a User account.
Literature including the MAN pages suggests there are differences in environmentals and paths, that “su -” is the equivalent of logging in to a new session as root, whereas “su” continues to use the ordinary User’s environmentals including home directory, path, etc.
I have found that at least on openSUSE, for the most part that’s false…
There are only two minor differences…
- The cursor’s starting point. When you “su” the cursor remains where you executed the command. When you “su -” the cursor starts in the User root’s home directory.
- In each case you can execute “printenv” to list all environmental variables that aren’t exported. When I did this, only a few XDG configurations and settings were located in the ordinary User’s home directory which can be called almost insignificant… Does it matter where settings and configurations are stored as long as they are accessible? How important is it that a GUI setting might be shared between root and the ordinary User?
printenv
Aside from those two items,
Everything else appears to be identical…
Same home directory
Same permissions to access resources on the system.
Same $PATH, in fact all other non-XDG variables appear to be identical.
So,
Bottom line is that should you decide to “su” instead of "su - " the only significant thing to remember is that your cursor is still wherever it happens to be and if you want to be in root’s home directory, you would have to cd as follows
cd ~/
But,
If you’re looking for any kind of differences in security, use and behavior, there aren’t any.
Again, reminding that we are not talking about switching to a specified User account other than root which has different consequences.
Am I missing something?
TSU