su
and su -
are Unix commands used to switch the user account in a terminal session. The key differences are:
su
- Switches to the specified user account without changing the environment variables or the current working directory.
- Maintains the environment variables of the user who executed the command.
- Defaults to the root user if no username is provided.
- Syntax:
su [username]
su -
- Switches to the specified user account and simulates a full login by loading the target user’s environment variables.
- Defaults to the root user if no username is provided.
- Syntax:
su - [username]
Both commands require the password of the target user (root, if no username is provided) to complete the switch.