Skip to content

Different types of user switch on Linux

1、以登录式shell切换用户

su - username

登录式shell读取配置文件及其顺序:

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

2、以非登陆式shell切换用户

su username

非登陆式shell读取配置文件及其顺序:

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

附:bash配置文件

(1) 全局配置文件

/etc/profile
/etc/profile.d/*.sh
/etc/bashrc

(2) 用户个人配置文件

~/.bash_profile
~/.bashrc

其中:

  • profile类配置:设置环境变量,执行登陆后自动运行的命令或脚本
  • bashrc类配置:设定本地变量,设定别名

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App