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

Linux 系統崩潰救援模式實戰:root 密碼重置與系統修復全流程

編輯:Linux 教學

適用場景

  • root 密碼遺失或被竄改
  • 關鍵系統文件(/etc/passwd、/etc/shadow、/etc/fstab)損壞
  • 啟動載入器(GRUB/LILO)損壞導致無法引導
  • 文件系統錯誤需要手動 fsck 修復

救援模式進入步驟

  1. 介質啟動:插入系統安裝光盤/USB,BIOS 設置光驅優先啟動
  2. 進入救援:啟動畫面按 F5,輸入 linux rescue 回車
  3. 語言鍵盤:保持默認英語/美式鍵盤,直接回車跳過
  4. 掛載系統:安裝程序自動掛載原系統至 /mnt/sysimage,出現 # 提示符即進入救援環境

root 密碼清空實操

# 進入原系統 etc 目錄
cd /mnt/sysimage/etc

# 備份關鍵文件
cp shadow shadow.bak

# 修改 shadow 文件屬性為可寫
chmod +w shadow

# 使用 vi 編輯 shadow
vi shadow
# 找到 root 行:root:$6$salt$hash:... 
# 刪除第一個冒號與第二個冒號之間的加密哈希值(保留冒號)
# 修改後:root::... 即為空密碼

# 恢復只讀屬性
chmod -w shadow

# 退出救援模式
exit

無 vi 環境替代方案

# 需準備 DOS 格式軟盤
mcopy shadow a:/          # 複製到軟盤
# Windows 記事本打開(選「所有文件」)修改保存
mcopy a:/shadow /mnt/sysimage/etc/shadow  # 複製回去

救援後必做操作

  1. 重啟進入系統,立即執行 passwd root 設置強密碼
  2. 檢查 /etc/fstab 掛載配置是否正確
  3. 執行 fsck -y /dev/sdX 檢查修復文件系統
  4. 若 GRUB 損壞,執行 grub-install /dev/sda 重裝引導器

進階救援技巧

chroot 完全接管原系統

mount -o bind /dev /mnt/sysimage/dev
mount -o bind /proc /mnt/sysimage/proc
mount -o bind /sys /mnt/sysimage/sys
chroot /mnt/sysimage /bin/bash
# 此後可直接運行 rpm、yum、systemctl 等原生命令

SELinux 環境下的密碼修復

# 修改 shadow 後需恢復安全上下文
restorecon /etc/shadow
# 或臨時關閉 SELinux 驗證
setenforce 0
Copyright © Windows教程網 All Rights Reserved