Skip to content

Different types of user switch on Linux

homepage-banner

1. Switching users with login shell

su - username

The login shell reads the configuration files in the following order:

  1. /etc/profile
  2. /etc/profile.d/*.sh
  3. ~/.bash_profile
  4. ~/.bashrc
  5. /etc/bashrc

2. Switching users with non-login shell

su username

The non-login shell reads the configuration files in the following order:

  1. ~/.bashrc
  2. /etc/bashrc
  3. /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
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.com, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No personal information is collected.
Feedback