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

RHEL 6 修改 root 密碼的三種非常規方法

編輯:Linux 教學

背景

RHEL 5 單用戶模式直接 passwd 即可修改 root 密碼,但 RHEL 6 增加了 SELinux 防護導致該方法失效。

方法一:單用戶模式 + 關閉 SELinux(推薦)

  1. 啟動 GRUB 選單,按 e 編輯內核行,尾部加 single 或 rd.break
  2. 進入單用戶模式(掛載為只讀,需重掛載):
    mount -o remount,rw /sysroot
    chroot /sysroot
  3. 暫時關閉 SELinux 強制模式:
    setenforce 0
  4. 修改密碼:
    passwd
  5. 重啟:
    reboot

方法二:暴力修改 /etc/passwd(不推薦生產環境)

  1. 進入單用戶模式並 chroot /sysroot
  2. 編輯 vi /etc/passwd,找到 root 行:
    root:x:0:0:root:/root:/bin/bash
  3. 刪除第二欄的 x:
    root::0:0:root:/root:/bin/bash
  4. 退出 chroot,init 5 進圖形模式
  5. 以 root 免密登入,執行 passwd 設定新密碼

方法三:使用安裝光碟救援模式(標準流程)

  1. 光碟啟動選擇 Rescue installed system
  2. 掛載系統至 /mnt/sysimage
  3. chroot /mnt/sysimage
  4. passwd 修改密碼
  5. exit → reboot

注意事項

  • 方法二會導致影子密碼文件不同步,修改後務必執行 pwconv 同步
  • 生產環境強烈建議使用方法一或三
  • 修改後檢查 /etc/shadow root 行第二欄已為加密雜湊值
Copyright © Windows教程網 All Rights Reserved