SELinux導致登入不進Linux系統的問題與解決
冷勝魁(Seaquester)
lengshengkui@gmail.com
2008-6-4
最近在做Linux USB啟動盤時遇到一個問題:用隨身碟啟動,輸入使用者名稱和密碼之後,螢幕快速的閃過一段提示,然後重新出現login>提示符,始終登入不進去。讓我鬱悶了好久,在網上搜尋了好久,也沒有找到答案。
後來我懷疑到SELinux(我的USB啟動盤是在Fedora Core 6下面做的,FC6裡面有SELinux,隨身碟的Rootfs裡面的檔案都是從FC6裡面copy過來的)。在隨身碟的 /var/log/messages 裡面看到這樣的資訊:
May 28 20:59:43 localhost kernel: audit(1168261183.296:4): avc: denied { entrypoint } for pid=2118 comm="login" name="bash" dev=sda1 ino=77521 scontext=root:system_r:hotplug_t:s0-s0:c0.c1023 tcontext=root:object_r:file_t:s0 tclass=file
May 28 21:00:00 localhost kernel: audit(1168261200.421:5): avc: denied { entrypoint } for pid=2120 comm="login" name="bash" dev=sda1 ino=77521 scontext=root:system_r:hotplug_t:s0-s0:c0.c1023 tcontext=root:object_r:file_t:s0 tclass=file
所以我嘗試著在隨身碟的系統裡面關掉SELinux,就可以登入進去了。
關閉方法:
1) 在grub.conf裡面加一個kenrnel的參數(selinux=0):kernel /boot/vmlinuz-2.6.18-1.2798.fc6 ro root=LABEL=ROOT_USB selinux=0
2)修改 /etc/selinux/config 檔案,將 SELINUX=Enforcing 改為 SELINUX=disabled。
進一步研究了一下 SELinux,發現,原來是因為Copy到隨身碟上面的檔案的security context變化了(用ls -Z就可以看到),應該在copy的時候加上-Z參數,如:
cp -aZ <source> <dest>