How to Simulate a Login Shell
To simulate a full login shell for another user, use the ‘-l’ or ‘–login’ option:
su -l username
This ensures that the target user’s environment is fully loaded, just like during a regular login.
This command switches to the root user while preserving the environment.
Switch Users on Linux with the su Command
Switching users on a Linux system is a fundamental aspect of system administration, allowing users to perform tasks with different privileges. The ‘su’ command, short for “switch user” or “substitute user,” is a powerful tool that facilitates this transition. This article will delve into the intricacies of the ‘su’ command, exploring its various options and providing practical examples to demonstrate its usage.
Table of Content
- Understanding the su Command
- Basic Syntax of su Command
- Options Available in su Command
- How to Switch to the Root User by Using su Command
- How to Switch to the Specific User by Using su Command
- How to Execute a Command as Another User by Using su Command
- How to Preserve Environment Variables while Switching User
- How to Simulate a Login Shell