Ubuntu 系列系統忘記 root 密碼,通用解法是通過 GRUB 進入單用戶模式(Single User Mode)掛載根分區為讀寫,直接修改 /etc/shadow。本文梳理通用操作流程(適用 Ubuntu 14.04/16.04/18.04/20.04+)。


linux 開頭的行,將 ro recovery nomodeset 修改為 rw single init=/bin/bash。# 原行
linux /boot/vmlinuz-xxx root=UUID=xxx ro recovery nomodeset
# 修改為
linux /boot/vmlinuz-xxx root=UUID=xxx rw single init=/bin/bash
rw:讀寫掛載根分區(必須,否則 passwd 無法寫入)。single / init=/bin/bash:進入單用戶 Shell,繞過正常啟動流程。root@(none):/# 提示符。passwd root 輸入新密碼兩次。sync
reboot -f
rw,執行 mount -o remount,rw / 後重試。touch /.autorelabel 並重啟兩次。grub-mkpasswd-pbkdf2 生成哈希 → 寫入 /etc/grub.d/40_custom → update-grub。核心口訣: Shift/Esc 進 GRUB → e 編輯 recovery 行 → ro 改 rw 加 init=/bin/bash → Ctrl+x 啟動 → passwd root → reboot。