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:
- Boot your device from the Ubuntu live media, and select "Try Ubuntu" to enter the live desktop environment.
- Identify your system's main partition: Open a terminal and run
lsblk—look for the partition with theext4filesystem (usually something like/dev/sda2or/dev/nvme0n1p2depending on your disk type). - Mount your system partition:
If you have a separate EFI partition (common on UEFI systems), mount it too:sudo mkdir /mnt/ubuntu sudo mount /dev/your-system-partition /mnt/ubuntusudo mount /dev/your-efi-partition /mnt/ubuntu/boot/efi - Enter the chroot environment to access your local system:
sudo chroot /mnt/ubuntu - Remove the faulty Grub password configuration:
Open the custom Grub config file with a text editor:
Look for lines you added earlier related to Grub authentication (likenano /etc/grub.d/40_customset superusers="root"orpassword root ...). Delete these lines, or comment them out by adding a#at the start of each line. Save the file (pressCtrl+O, thenEnter, thenCtrl+Xto exit nano). - Update Grub to apply the changes:
update-grub - Exit chroot and reboot:
Remove the live media when prompted, and your system should boot normally again.exit sudo reboot
正确设置Grub恢复模式密码(避免再次出错)
Once you're back in your system, here's the correct way to set a password for recovery mode only:
- Generate an encrypted password for Grub:
Run this command in the terminal, then follow the prompts to enter your desired password twice:
Copy the long encrypted string that starts withgrub-mkpasswd-pbkdf2grub.pbkdf2.sha512...—you'll need this next. - Edit the custom Grub config:
Add these lines (replacesudo nano /etc/grub.d/40_customyour-usernamewith 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] - Update Grub to apply the correct configuration:
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.sudo update-grub
备注:内容来源于stack exchange,提问作者a noob
相关产品推荐
相关产品推荐

