Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

CentOS 5.5 禁止單用戶模式:GRUB 設定密碼防護提升安全性

編輯:關於 Linux

單用戶模式(Runlevel 1)允許無密碼取得 root shell,攻擊者可重設 root 密碼。透過為 GRUB 開機選單設定密碼,可強制進入單用戶模式前需輸入 GRUB 密碼,有效阻擋實體存取攻擊。

操作步驟

1. 產生 GRUB 密碼雜湊 (MD5)

grub-md5-crypt
# 輸入兩次密碼,輸出範例:
# $1$abc123$def456ghi789jkl0
# 複製此字串

2. 編輯 GRUB 設定檔

vi /boot/grub/grub.conf
# 在 splashimage 行下方新增:
password --md5 $1$abc123$def456ghi789jkl0
# 完整範例:
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
password --md5 $1$abc123$def456ghi789jkl0
title CentOS 5.5
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.18-194.el5.img

3. 重啟驗證

reboot
# 開機 GRUB 選單出現,按 p 輸入密碼後才能編輯(e)或進入命令列(c)

替代:明文密碼(不推薦)

password myplainpassword
# 設定檔可見密碼,安全性極低,僅供測試環境

grub-md5-crypt 產生雜湊截圖

grub.conf 加入 password 行截圖

GRUB 選單密碼提示截圖

注意事項

  • GRUB 密碼遺失:需用 LiveCD 掛載 /boot 分區編輯 grub.conf 移除 password 行。
  • 此法僅防護 GRUB 選單編輯,無法防禦 LiveCD/單用戶模式直接掛載磁碟修改影子檔。生產環境建議結合 BIOS/UEFI 密碼、磁碟加密(LUKS)、實體機箱鎖。
  • CentOS 6/7 使用 GRUB2,配置檔為 /etc/grub.d/40_custom + grub2-mkconfig,設定方式不同。
Copyright © Windows教程網 All Rights Reserved