Switch the current terminal to user backup and load a login-style HOME, PATH, and related environment.
Which command is appropriate?
su - USER starts a login shell and initializes the target user's login environment. It differs from non-login su USER.
Detailed explanation
su - backupCorrect. su - backup starts backup's login shell.
Correct. su - backup starts backup's login shell.
su backupIncorrect. su backup changes user but preserves more of the current environment.
Incorrect. su backup changes user but preserves more of the current environment.
sudo -l backupIncorrect. sudo -l lists policy and does not start a shell.
Incorrect. sudo -l lists policy and does not start a shell.
su --preserve-environment backupIncorrect. Preserving the environment is the opposite of the requirement.
Incorrect. Preserving the environment is the opposite of the requirement.
Try it yourself
An example you can run in a temporary verification environment.
su --help 2>&1 | grep -E -- '-l|--login' | head -n 1Expected result
login shellに関するhelp行Key points
- Hyphen means login shell
- Initialize target environment
- Different from su USER
Notes
- Environment: util-linux su help / user切替なし
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.