LX0-103 · Question #24
You logged in as user tuxl, but now you want to switch users to tux2 with tux2's environment. How would you do this?
The correct answer is C. su - tux2. Running 'su - tux2' switches to tux2 and starts a full login shell that loads tux2's complete environment, including profile scripts and variables like HOME and PATH.
Question
You logged in as user tuxl, but now you want to switch users to tux2 with tux2's environment. How would you do this?
Options
- Asu tux2
- Bsu-etux2
- Csu - tux2
- Dsu -m tux2
- Esu-ftux2
How the community answered
(36 responses)- A3% (1)
- C89% (32)
- D3% (1)
- E6% (2)
Why each option
Running 'su - tux2' switches to tux2 and starts a full login shell that loads tux2's complete environment, including profile scripts and variables like HOME and PATH.
su tux2 without a hyphen switches the UID to tux2 but does not run tux2's login scripts, so the original user's environment variables like HOME and PATH remain unchanged.
su-etux2 is a malformed string and not a valid command; it does not correspond to any legitimate syntax for the su utility.
The hyphen (-) argument to su simulates a full login for the target user by executing that user's login initialization scripts (such as .bash_profile or .profile) and setting environment variables to the target user's values. Without the hyphen, su changes the user identity but inherits the calling user's environment, which does not satisfy the requirement of having tux2's environment.
su -m (or su -p) explicitly preserves the calling user's environment variables rather than loading the target user's environment, which is the opposite of the desired behavior.
su-ftux2 is a malformed string and not a valid command; no recognized su option produces this form.
Concept tested: su command with login shell flag for full environment switch
Source: https://man7.org/linux/man-pages/man1/su.1.html
Topics
Community Discussion
No community discussion yet for this question.