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 密碼重置與破解方法總彙整 (Grub/單用戶/救援模式)

編輯:Linux 教學

遺忘 Root 密碼是系統管理常見情境。本文彙整各主流 Linux 發行版 (CentOS/RHEL、Debian/Ubuntu、FreeBSD、Solaris 等) 的密碼重置方法,涵蓋 Grub 編輯、單用戶模式、救援模式、LiveCD 等多種手段。

一、正常情況下修改密碼

# 以 root 登入時
passwd root          # 修改 root 密碼
useradd username     # 新增用戶
passwd username      # 設定用戶密碼

二、通用 Grub 單用戶模式重置 (適用 CentOS/RHEL/Fedora)

  1. 開機 Grub 選單按 e 進入編輯模式
  2. 選中 kernel 行,再按 e 編輯
  3. 行尾加入 single 或 1 或 init=/bin/bash
  4. 按 Enter 確認,再按 b 啟動
  5. 進入單用戶模式後執行:
# 若為 init=/bin/bash 需重新掛載根分區為可寫
mount -o remount,rw /
passwd root
sync
mount -o remount,ro /
reboot

三、Debian/Ubuntu 專用模式

方法一:Recovery Mode (推薦)

  1. Grub 選單選擇 recovery mode 項目
  2. 選擇 root - Drop to root shell prompt
  3. 執行:
mount -o remount,rw /
passwd root
reboot

方法二:Grub 編輯 init=/bin/bash

  1. Grub 選單按 e 編輯 kernel 行
  2. 將 ro single 改為 rw single init=/bin/bash
  3. 按 b 啟動
  4. 執行:
mount -a
passwd root
reboot

四、FreeBSD 系統

  1. 開機選單選擇選項 4 進入單用戶模式
  2. 執行:
mount -a
fsck -y
passwd root
reboot

五、Solaris 系統

  1. Grub 選擇 solaris failsafe
  2. 提示掛載根分區時選 y (讀寫模式)
  3. 執行:
passwd root
reboot

六、NetBSD 系統

  1. 開機倒數時輸入 boot -s 進入單用戶模式
  2. Shell 提示符按 Enter 確認
  3. 執行:
mount -a
fsck -y
passwd root
exit  # 進入多用戶模式

七、Lilo 引導載入器 (舊版系統)

# Lilo 提示符下輸入
linux single
# 進入後
passwd root
reboot

八、LiveCD/安裝光碟救援模式 (萬能方法)

  1. 插入安裝光碟,BIOS 設定光碟啟動
  2. 啟動畫面按 F5,輸入 linux rescue 進入救援模式
  3. 選擇語言/鍵盤,系統會掛載原系統至 /mnt/sysimage
  4. 執行:
chroot /mnt/sysimage
passwd root
exit
reboot

或手動編輯 shadow 檔清空密碼:

cd /mnt/sysimage/etc
cp shadow shadow.bak
chmod +w shadow
vi shadow
# 找到 root 行,刪除第二欄雜湊值 (冒號保留)
# root:$6$hash...:... → root::...:
chmod -w shadow
reboot

九、安全性建議

  • 重置密碼後立即設定強密碼
  • 啟用 Grub 密碼保護防止單用戶模式被濫用:grub2-setpassword
  • 實體機房加強實體安全控管
  • 考慮使用 SSH 金鑰認證禁用密碼登入
Copyright © Windows教程網 All Rights Reserved