A system administrator needs to troubleshoot a user's application. The application's scripts rely on environment variables that are set in the user's .bash_profile file. The administrator must switch from their own account to the user's account, app_user, and ensure that the new session fully emulates a direct login by app_user to load the necessary environment. Which of the following commands should the administrator use?
The correct command is su - app_user. The - flag (which is a synonym for -l or --login) is crucial because it starts a login shell. A login shell simulates a fresh login, sourcing the target user's login scripts like /etc/profile and ~/.bash_profile. This action loads all the necessary environment variables and sets the working directory to the target user's home directory. The command su app_user only switches the user ID but retains most of the original user's environment, which would not load the required .bash_profile settings. The sudo -u app_user bash command runs a new shell as the target user but does not start it as a login shell, so it would not source .bash_profile. The login app_user command is used to log in from a terminal prompt and is not typically used to switch users within an existing shell session.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `-` option in the `su -` command do?
Open an interactive chat with Bash
How does `su -` differ from `sudo -u` when switching users?
Open an interactive chat with Bash
Why isn't the `login` command suitable for switching to another user within an active session?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Security
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access