- Authors
- Name
Overview
When using Linux, there are times when you need to log in as the superuser root without logging out of the current account. The commands used for this are su root or su - root. By default, if no user name is specified, the su command logs in as root. Let's look at the difference between the su and su - commands for switching users.
su (Switch User) Command
When you enter the su command in the shell, it switches to the root user while keeping the current environment variables.
su
su - (Switch User) Command
When you enter su - in the shell, it logs in as root and also changes the directory to root's home directory. The previous environment variables are discarded.
sh -
In this case, the environment variables defined in ~/.bash_profile or ~/.bashrc under the root account are loaded.
In summary, the difference between the su and su - commands is whether or not the previous user's environment variables are loaded before the dash. This concludes the post about the Linux commands for switching users. Thank you.