login shell

最近接到一个WebShell用户反馈,即debian系统-终端登陆发现没有加载~/.profile. 这里经过分析是底层开启的交互式非登陆Shell没有走登陆Shell导致。

登陆Shell

登陆Shell会加载 ~/.bash_profile, .profile,/etc/profile文件,非登陆Shell不会加载这些,但会加载~/.bashrc

profile加载顺序

  1. /etc/profile:首先,Shell 会读取系统范围内的全局配置文件 /etc/profile。
  2. ~/.bash_profile, ~/.bash_login, 和 ~/.profile(按此顺序),Shell 会查找并尝试执行用户的个人配置文件。它首先检查 ~/.bash_profile,如果这个文件存在,则停止读取其他文件。如果 ~/.bash_profile 不存在,它会查找 ~/.bash_login。如果这个文件也不存在,最后会尝试读取 ~/.profile。