“login shell” 代表用户登入, 比如使用 “su -“ 命令, 或者用 ssh 连接到某一个服务器上, 都会使用该用户默认 shell 启动 login shell 模式.
该模式下的 shell 会去自动执行 /etc/profile 和 ~/.profile 文件, 但不会执行任何的 bashrc 文件, 所以一般再 /etc/profile 或者 ~/.profile 里我们会手动去 source bashrc 文件.
而 no-login shell 的情况是我们在终端下直接输入 bash 或者 bash -c “CMD” 来启动的 shell.
该模式下是不会自动去运行任何的 profile 文件.
1.login shell与non-login shell的概念
(1)login shell
取得shell(如bash)时需要完整的登录流程,就称为login shell。举例来说,有tty1-tty6登录,输入用户的账户和密码后,取得的shell就称为“login shell”
(2)non-login shell
取得shell不需要账户登录的流程。比如说,在X window登录linux后,在桌面右击获取的命令行窗口,此时不需要用账户名和密码进行登录,那这个bash的环境就称为non-login shell。在比如,在bash中再次执行bash命令,获取到的子bash进程,也没有登录动作,这个子bash进程同样是non-login shell。
2.login shell和non-login shell的区别
login shell和non-login shell的核心区别就是在获取shell时,读取的配置文件不同。
(1)login shell读取的配置文件
- /etc/profile 该文件来设置系统的整体环境,通常是一些环境变量的配置。
- ~/.bash_profile或~/.bash_login或~/.profile三者中的一个,该文件是用户个人设置
(2)non-login shell读取的配置文件
- ~/.bashrc
首先,shell分为登录式shell和非登录时shell,两者的读取配置文件的顺序是不一样的.
登录式shell读取配置文件的顺序为 /etc/profile -> /etc/profile.d/*.sh -> ~/.bash.profile -> ~/.bashrc -> /etc/bashrc
非登录式shell读取配置文件的顺序为 ~/.bas