Different types of user switch on Linux
1、以登录式shell切换用户
su - username
登录式shell读取配置文件及其顺序:
- /etc/profile
- /etc/profile.d/*.sh
- ~/.bash_profile
- ~/.bashrc
- /etc/bashrc
2、以非登陆式shell切换用户
su username
非登陆式shell读取配置文件及其顺序:
- ~/.bashrc
- /etc/bashrc
- /etc/profile.d/*.sh
附:bash配置文件
(1) 全局配置文件
/etc/profile
/etc/profile.d/*.sh
/etc/bashrc
(2) 用户个人配置文件
~/.bash_profile
~/.bashrc
其中:
- profile类配置:设置环境变量,执行登陆后自动运行的命令或脚本
- bashrc类配置:设定本地变量,设定别名
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here