nerdexam
CompTIA

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.

GNU and Unix Commands

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)
  • A
    3% (1)
  • C
    89% (32)
  • D
    3% (1)
  • E
    6% (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.

Asu tux2

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.

Bsu-etux2

su-etux2 is a malformed string and not a valid command; it does not correspond to any legitimate syntax for the su utility.

Csu - tux2Correct

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.

Dsu -m tux2

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.

Esu-ftux2

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

#su command#user switching#login shell#environment variables

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice