In Linux, the `su` command allows a user to switch to a different user account. The `su` command can be followed by the name of the user to switch to, and will prompt the user for the password of the user they are trying to switch to.

Advertisement

The `su` command has a number of options that can be used to modify its behavior. One of these options is `-`, which stands for “login shell”. When the `-` option is used with the `su` command, it causes the su command to run a login shell for the specified user. This means that the user’s environment variables and profile scripts will be sourced as if they had logged in to the system normally.

For example, to switch to the root user and run a login shell, you would use the following command:

su - root 

Check for the system environment after switching to the root user.

`su – root` command example

On the other hand, if you omit the `-` option and just use the `su` command by itself, it will switch to the specified user without running a login shell. This means that the user’s environment variables and profile scripts will not be sourced, and the user will be in the same environment as before they switched users.

For example, to switch to the root user without running a login shell, you would use the following command:

su root 

See the system environment after switching to the root user.

`su root` command example

In summary, the difference between `su` and `su -` is that `su` switches to the specified user without running a login shell, while `su -` switches to the specified user and runs a login shell. It’s important to understand this difference, as it can affect the environment in which you are working when switching to a different user account.

Share.

Leave A Reply