理清login shell与non-login shell

接下来在此想彻底理清bash的login shell与non-login shell
说老实话,到现在我还没用过login shell(没用过tty1~tty6的文字登入模式啦),也就是说,都是在X 介面下启动的终端而已,所以基本都是non-login shell~~

定义:
login shell :取得bash 时需要完整的登入流程,就称为login shell。举例来说,同tty1~tty6登入时, 

需要输入用户名和密码,此时取得的bash就称为login shell

non-login shell :取得bash介面的方法不需要重复登入的动作。
举两个例子(1)以X window登入linux后,再以X 的图形化介面启动终端机,此时那个终端机并不需要再次的输入用户名和密码,那个bash的环境就称为non-login shell
(2)在原本的bash环境中再次下达bash这个指令,同样没有要求输入用户名和密码,那个第二个bash也是non-login shell


在这两个取得bash的情况中,所读取的设定档并不一样 (以下引用鸟哥)

login shell 其實只會讀取這兩個設定檔:
  1. /etc/profile:這是系統整體的設定,你最好不要修改這個檔案;
  2. ~/.bash_profile 或 ~/.bash_login 或 ~/.profile:屬於使用者個人設定,你要改自己的資料,就寫入這裡
/etc/profile只有login shell 会读,每個使用者登入取得 bash 時一定会读取的设定档 !所以如果你想要帮所有使用者设定整体环境,那就是改这里
同样, /etc/profile会去呼叫外部的设定资料 ,底下这些资料会 依次 被呼叫进来:(底下引自鸟哥)

/etc/inputrc: 其實這個檔案並沒有被執行啦!/etc/profile 會主動的判斷使用者有沒有自訂輸入的按鍵功能,如果沒有的話, /etc/profile 就會決定設定『INPUTRC=/etc/inputrc』這個變數!此一檔案內容為 bash 的熱鍵啦、[tab]要不要有聲音啦等等的資料! 因為鳥哥覺得 bash 預設的環境已經很棒了,所以不建議修改這個檔案!

/etc/profile.d/*.sh :其實這是個 目錄 內的眾多檔案 !只要在 /etc/profile.d/ 這個目錄內且副檔名為 .sh ,另外, 使用者能夠具有 r 的權限 ,那麼該檔案就會被 /etc/profile 呼叫進來。在 CentOS 5.x 中,這個目錄底下的檔案規範了 bash 操作介面的顏色、 語系、ll 與 ls 指令的命令別名、vi 的命令別名、which 的命令別名等等。如果你需要幫所有使用者設定一些共用的命令別名時, 可以在這個目錄底下自行建立副檔名為 .sh 的檔案,並將所需要的資料寫入即可喔!

/etc/sysconfig/i18n :這個檔案是 由 /etc/profile.d/lang.sh 呼叫進來的 !這也是我們決定 bash 預設使用何種語系的重要設定檔!檔案裡最重要的就是 LANG 這個變數的設定啦

反正你只要記得, bash 的 login shell 情況下所讀取的整體環境設定檔其實只有 /etc/profile ,但是 /etc/profile 還會呼叫出其他的設定檔,所以讓我們的 bash 操作介面變的非常的友善啦


个人设定:

~/.bash_profile ( login shell 才會讀 )

bash 在讀完了整體環境設定的 /etc/profile 並藉此呼叫其他設定檔後,接下來則是會讀取使用者的個人設定檔。 在 login shell 的 bash 環境中 ,所讀取的個人偏好設定檔其實主要有三個,依序分別是:

  1. ~/.bash_profile
  2. ~/.bash_login
  3. ~/.profile

其實 bash 的 login shell 設定只會讀取上面三個檔案的其中一個, 而讀取的順序則是依照上面的順序 。 也就是說,如果 ~/.bash_profile 存在,那麼其他兩個檔案不論有無存在,都不會被讀取。 如果 ~/.bash_profile 不存在才會去讀取 ~/.bash_login,而前兩者都不存在才會讀取 ~/.profile 的意思。會有這麼多的檔案,其實是因應其他 shell 轉換過來的使用者的習慣而已
bash 設定檔的讀入方式比較有趣,主要是透過一個指令『 source 』來讀取的! 也就是說 ~/.bash_profile 其實會再呼叫 ~/.bashrc 的設定內容喔,login shell 環境下,最終被讀取的設定檔是『 ~/.bashrc 』這個檔案

~/.bashrc (non-login shell 會讀)
談完了 login shell 後,那麼 non-login shell 這種非登入情況取得 bash 操作介面的環境設定檔又是什麼? 當你取得 non-login shell 時,該 bash 設定檔僅會讀取 ~/.bashrc 而已啦
不过~/.bashrc会去呼叫/etc/bashrc.而这个/etc/bashrc主要有三个作用“
1.根据不同的UID,规范出UMASK的值
2.依据不同的UID ,规范出PS1, 也就是提示符的内容
3.呼叫/etc/profile.d/*sh目录中的内容

引自:http://linux.vbird.org/linux_basic/0320bash.php

from:http://seufy-281412.spaces.live.com/blog/cns!A6558DF0C9940C82!688.entry

 

************************************************************************************************

Login shells
/etc/profile
/etc/profile.d
~/.bash_profile
~/.bashrc
/etc/bashrc

#########################
Non-login shells
~/.bashrc
/etc/bashrc
/etc/profile.d

login nologin shell的推行 序次 服从上述序次 推行 .

#########################
查察 /etc/profile
#cat /etc/profile
有以下内容,阐发 了推行 /etc/profile.d/里的*.sh
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

/etc/profile.d内里有以下脚本
-rwxr-xr-x  1 root root  720 Apr 11  2006 colorls.csh
-rwxr-xr-x  1 root root  713 Apr 11  2006 colorls.sh
-rwxr-xr-x  1 root root  192 Oct 13  2004 glib2.csh
-rwxr-xr-x  1 root root  190 Oct 13  2004 glib2.sh
-rwxr-xr-x  1 root root   58 May  2  2006 gnome-ssh-askpass.csh
-rwxr-xr-x  1 root root   70 May  2  2006 gnome-ssh-askpass.sh
-rwxr-xr-x  1 root root   78 Jan 11  2006 kde.csh
-rwxr-xr-x  1 root root   74 Jan 11  2006 kde.sh
-rwxr-xr-x  1 root root  218 Feb  7  2006 krb5.csh
-rwxr-xr-x  1 root root  210 Feb  7  2006 krb5.sh
-rwxr-xr-x  1 root root 2182 Apr 21  2006 lang.csh
-rwxr-xr-x  1 root root 2470 Apr 21  2006 lang.sh
-rwxr-xr-x  1 root root  122 Jun 16  2004 less.csh
-rwxr-xr-x  1 root root  108 Jun 16  2004 less.sh
-rwxr-xr-x  1 root root   51 Nov 19  2004 mc.csh
-rwxr-xr-x  1 root root   45 Nov 19  2004 mc.sh
-rwxr-xr-x  1 root root  102 Nov 25  2004 qt.csh
-rwxr-xr-x  1 root root   99 Nov 25  2004 qt.sh
-rwxr-xr-x  1 root root   13 Aug 11  2005 vim.csh
-rwxr-xr-x  1 root root  181 Aug 11  2005 vim.sh
-rwxr-xr-x  1 root root  170 Aug  7  2004 which-2.sh


当推行 完上述全部脚本之后,会推行 当前帐户下的~/.bash_profile文件,该文件有此中以下内容,阐发 会具体 推行 ~/.bashr的内容
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

#vi ~/.bashrc
有以下内容
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

看来login shell终极会推行 /etc/bashrc 这个脚本

nologin shell

服从上面的思绪可以看到 nologin的推行 序次 ,验证的行动可在每个文件上应用 echo 来验证

 

from: http://linux.net527.cn/Linuxwendang/xitongguanliyuan/24944.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值