How to Preserve Environment Variables while Switching User
When switching users, you might want to preserve the environment variables from the original user. Use the ‘-‘ option to achieve this:
sudo su -
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