You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GNU Grub恢复模式密码操作失误致Ubuntu 22.04设备锁定,咨询默认密码问题

GNU Grub恢复模式密码操作失误致Ubuntu 22.04设备锁定,咨询默认密码问题

Hey there, let's sort this out for you first: there is no default Grub password whatsoever. Grub doesn't come with any pre-set password protection out of the box—this is exactly why you're locked out right now. You added configuration to force authentication on boot, but failed to set a valid encrypted password, so the system has no valid credentials to accept, leading to the lockout.

如何恢复正常访问你的Ubuntu系统

Follow these steps to fix the lockout using an Ubuntu 22.04 live USB/CD:

  1. Boot your device from the Ubuntu live media, and select "Try Ubuntu" to enter the live desktop environment.
  2. Identify your system's main partition: Open a terminal and run lsblk—look for the partition with the ext4 filesystem (usually something like /dev/sda2 or /dev/nvme0n1p2 depending on your disk type).
  3. Mount your system partition:
    sudo mkdir /mnt/ubuntu
    sudo mount /dev/your-system-partition /mnt/ubuntu
    
    If you have a separate EFI partition (common on UEFI systems), mount it too:
    sudo mount /dev/your-efi-partition /mnt/ubuntu/boot/efi
    
  4. Enter the chroot environment to access your local system:
    sudo chroot /mnt/ubuntu
    
  5. Remove the faulty Grub password configuration:
    Open the custom Grub config file with a text editor:
    nano /etc/grub.d/40_custom
    
    Look for lines you added earlier related to Grub authentication (like set superusers="root" or password root ...). Delete these lines, or comment them out by adding a # at the start of each line. Save the file (press Ctrl+O, then Enter, then Ctrl+X to exit nano).
  6. Update Grub to apply the changes:
    update-grub
    
  7. Exit chroot and reboot:
    exit
    sudo reboot
    
    Remove the live media when prompted, and your system should boot normally again.

正确设置Grub恢复模式密码(避免再次出错)

Once you're back in your system, here's the correct way to set a password for recovery mode only:

  1. Generate an encrypted password for Grub:
    Run this command in the terminal, then follow the prompts to enter your desired password twice:
    grub-mkpasswd-pbkdf2
    
    Copy the long encrypted string that starts with grub.pbkdf2.sha512...—you'll need this next.
  2. Edit the custom Grub config:
    sudo nano /etc/grub.d/40_custom
    
    Add these lines (replace your-username with your actual Ubuntu username, and paste the encrypted string you copied):
    set superusers="your-username"
    password_pbkdf2 your-username grub.pbkdf2.sha512.10000...[your-encrypted-string]
    
  3. Update Grub to apply the correct configuration:
    sudo update-grub
    
    Now, when you boot into recovery mode, it will prompt for your username and the password you set, while normal boot will work without any prompts.

备注:内容来源于stack exchange,提问作者a noob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 12:32:58