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 密碼不必重灌系統。本文整理五種實測可行的恢復方式,適用 Red Hat 系列,其他 Unix/Linux 亦可參考。

方法一:緊急修復模式 (Rescue Mode)

用安裝光碟啟動,選擇 linux rescue,掛載硬碟分割區至 /mnt/sysimage,進入 chroot 環境修改密碼或編輯 /etc/shadow。

方法二:單用戶模式 (Single User Mode / Runlevel 1)

  1. 開機選單 (GRUB) 按 e 編輯核心參數,行尾加 single 或 1。
  2. 啟動後直接進入 root shell,無需密碼。
  3. 執行 passwd 重設密碼,或直接編輯 /etc/passwd//etc/shadow。

方法三:直接修改密碼檔

  • 無 Shadow 檔: 編輯 /etc/passwd,將 root 密碼欄位清空(root::0:0:...)。
  • 有 Shadow 檔: 編輯 /etc/passwd 將 x 移除,或編輯 /etc/shadow 清空密碼雜湊。

修改後即可免密碼登入,再用 passwd 設定新密碼。

方法四:密碼破解 (John the Ripper 等)

針對 /etc/shadow 雜湊進行字典/暴力破解,僅適用「找回原密碼」需求。工具:John the Ripper、Crack。複雜密碼極難破解,耗時極長。

方法五:線上系統攻擊 (不建議自行嘗試)

針對運行中服務的已知漏洞提權,風險極高,可能破壞資料。若業務關鍵無法停機,請尋求專業廠商協助。

總結建議

  1. 優先用單用戶模式或救援模式,風險最低。
  2. 修復後立即設定強密碼,並檢查 /etc/ssh/sshd_config 禁止 Root 遠端登入。
  3. 建立 sudo 權限帳號作日常管理,減少直接用 Root 登入。
Copyright © Windows教程網 All Rights Reserved