2012年7月21日 星期六

在Linux上一個UID只能給一個帳號名稱使用嗎??(未完成)

如題,站在系統管理的角度上,原則上我們是希望一個使用都帳號只會對應一個UID。換言之,在新增一個使用者帳號時,會分配一個未用過的號碼作為新帳號的UID,而不會用一個已用過的號碼(也就是已經有其它帳號在使用的號碼),作為新帳號的UID。

不過如果去觀察指令「useradd」的man_page,可以發現一個選項「-o」,透過這個選項可以將已分配的UID重複分配給新增的帳號使用。這就會變成,一個UID會對應到2個以上的帳號名稱。

不過此時又會衍生另一個問題,假設現在有2個帳號「test1」和「test2」,這2個帳號對應同一個UID「600」,如果我們以UID=600在系統上操作時,我們到底是用哪一個帳號身份呢?是test1還是test2??

當我們在Login時,輸入的名稱假設叫作「typein_name」,透過typein_name對照「/etc/passwd」的資料,取得UID、GID、shell和家目錄位置(所以登入完成後所在的家目錄要看typein_name),接著,登入的shell讀取啟動檔來設定變數USER,變數USER的設定是透過執行命令行「id -un」,該命令行會以現在的UID號碼來查詢檔案「/etc/passwd」以取得帳號名稱,所以此時同樣的UID如有不同的帳號名稱,則先找到的那一筆紀錄,會先被使用。

這也就是為什麼登入時,明明在login的判面是輸入「A帳號」,登入完成後,家目錄是在「A帳號的家目錄」可是提示字元的使用者帳號名稱卻是顯示「B帳號」(因為B帳號的紀錄在檔案/etc/passwd中,排得位置比A帳號上面)。

有空的話我再把lab驗測式的圖檔放上來

2012年7月6日 星期五

quota (配額) 釋疑 (未完成)

       Linuxext234的檔案系統,可以作quota(配額)的設定,相關的指令工具有:

mount:
quotacheck:
quotaon/off:
repquota:
edquota:
quota:

     指令「quotaon」有一個選項「-a」,該選項的man_page說明如下:
All automatically mounted (no noauto option) non-NFS filesystems in /etc/fstab with quotas will have their quotas turned on. This is normally used at boot time to enable quotas.

        上面的內容易讓人誤解為「quotaon -a」,會去參考檔案「/etc/fstab」的內容來啟動檔案系統的quota功能。

其實不是這個意思。
基本上「quotaon -a」和「quotacheck -a」,這個選項「-a」都是去參考檔案「/etc/mtab」的內容來作quota的運作。

證明:
我們設計一個Lab環境:
1.在檔案「etc/fstab」裡頭加入一筆資料
/tmp/quota     /mnt/fs1    ext2   loop,auto,usrquota   0  0


2.重新開機,之後該檔案系統會在系統啟動時被自動掛載到系統,並啟動quota的功能。

3.緊接著,我們手動將這個檔案系統「/tmp/quota」卸載,執行命令行「mount -n -t ext2 -o loop,auto,usrquota /mnt/fs1」,重新掛載該檔案系統;由於指令「mount」的選項「-n」的作用在於〝會將檔案系統掛載,但卻不會將掛載的訊息更新到檔案「/etc/mtab」中〞。此時再執行「quotaon -a」時,會發現在該檔案系統的quota是沒用啟動的。

結論:quotaon -a基本上是參考檔案「/etc/mtab」。



2012年5月29日 星期二

2012年5月19日 星期六

解決Ubuntu上使用vi編輯時,方向鍵及倒退鍵(Backspace)操作失常的問題

Ubuntu上使用vi編輯器編輯時,有時會發現方向鍵和倒退鍵(Backspace)會失常。

如上圖

vi的輸入模式(inser mode)時:
1.輸入方向鍵會出現ABCD
2.倒退刪除鍵(Backspace)緅作用
此時,我們可以在家目錄底下,新增檔案「.vimrc」,在檔案中加入下列2行內容:
set nocompatible
set backspace=2
記得存檔後離開

接著再使用vi編輯器時便可正常使用方向鍵和倒退鍵(Backspace)了。

2012年3月16日 星期五

喔賣尬!原來這就是vi 的 h j k l (左下上右鍵) 的由來^______^"


I was reading about vim the other day and found out why it used hjkl keys as arrow keys. When Bill Joycreated the vi text editor he used the ADM-3A terminal, which had the arrows on hjkl keys. Naturally he reused the same keys and the rest is history!
Here is how the hjkl keys looked:

ADM-3A keyboard's hjkl keys with arrows.
And here is the whole terminal that vi was created on:

Lear Siegler's ADM-3A computer terminal.
Since vim is derived from vi, it uses the same hjkl keys.
And while we're at it, notice where the ESC key is positioned:

Lear Siegler's ADM-3A computer terminal's full keyboard.
That's why the ESC is used to change between vi modes! Because it's so close and easy to reach.
Also ever wondered why home directory is ~ in UNIX? Look at the HOME key in upper right corner!

HJKL T-Shirt!

I just got a deal with Teespring for a hjkl t-shirt! Teespring is like kickstarter for t-shirts. If at least 30 people commit to buy the shirt the deal goes through and everyone gets the shirt. Otherwise nothing happens.
Get your limited edition hjkl t-shirt now! (Ships worldwide in 4-8 days.)