Different types of user switch on Linux
1. Switching users with login shell
su - username
The login shell reads the configuration files in the following order:
- /etc/profile
- /etc/profile.d/*.sh
- ~/.bash_profile
- ~/.bashrc
- /etc/bashrc
2. Switching users with non-login shell
su username
The non-login shell reads the configuration files in the following order:
- ~/.bashrc
- /etc/bashrc
- /etc/profile.d/*.sh
Appendix: Bash Configuration Files
Where:
- Profile configuration: sets environment variables, executes commands or scripts automatically after login
- Bashrc configuration: sets local variables, sets aliases
Back to Table of Contents
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.com
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No personal information is collected.
Feedback