CentOS 7 如何重設 root 密碼?
在開機過程進入 grub 選單的時候,按 e 編輯開機選項
![](https://sam.liho.tw/wp-content/uploads/2020/08/Screen-Shot-2020-08-18-at-10.10.54-AM.png)
然後在 linux16 那一行找「ro」
![](https://sam.liho.tw/wp-content/uploads/2020/08/Screen-Shot-2020-08-18-at-10.12.41-AM.png)
把「ro」替換成下列指令「rw init=/sysroot/bin/sh」
![](https://sam.liho.tw/wp-content/uploads/2020/08/Screen-Shot-2020-08-18-at-10.13.00-AM.png)
然後按 Ctrl + X 離開,準備進入單人模式開機 (single user mode)
![](https://sam.liho.tw/wp-content/uploads/2020/08/Screen-Shot-2020-08-18-at-10.13.23-AM.png)
chroot 到系統內部
# chroot /sysroot
重設密碼
# passwd
如果有啟用 SELINUX 請記得 Auto Relabel
# touch /.autorelabel
離開 chroot
# exit
重新開機
# reboot
這樣 root 密碼就改好了