Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to reset root password and protect grub Startup menu by Linux

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains how Linux resets the root password and protects the grub startup menu. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to reset the root password and protect the grub startup menu by Linux.

Note: remember the spaces in the code

Step 01

Select the menu in the figure above: Machine--  Close  Power Off, and close CentOS Linux 7.

Step 02

On the VirtualBox main interface menu, click the Start button to start the virtual machine.

Step 03

When the grub menu appears, use the up and down arrow keys to select the top startup item and press the letter e.

Step 04

Locate the linux16 line, press end on the keyboard, and position the cursor at the end of the line.

Step 05

Delete to ro, delete o, write w, and type the space rd.break, that is, "rw rd.break" at the end of the line, as shown in the figure above.

Then press Ctrl-x

Step 06

Switch_root:/# chroot / sysroot

Chroot / sysroot, enter the prison / sysroot.

Sh_4.2# passwd root

Change the password of root.

Sh_4.2# touch /. Autorelabel

Re-tag the file system with SELinux.

Sh_4.2# exit

Get out of jail.

Switch_root:# exit

Protect the grub startup menu

Step 1: right-click the blank screen to open the terminal "open terminol" and enter the following command

# grub2-mkpasswd-pbkdf2

Enter password:123456

When Reenter password:123456 presses enter again, a series of codes PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.1B34404433526E5002B881AAD026E76B27713C1D26A1471C4907D5A31E86132920D23E5DC8E9DA211A24057CBE9384C158FF2892A26ECEDE790F8C6D3BB2C7BF.55D8820C747338D943E05484E457411F645FD6B7564A903D7CF6780528988AC6C998FB6B7DF67EC559039BC465970C82182D7FA5F36781DDB86FB40F47FE5269 will appear.

Step 2

# cp / etc/grub.d/40_custom / etc/grub.d/40_custom-bak

# cp / boot/grub2/grub.cfg / boot/grub2/grub.cfg-bak

Line 1, back up / etc/grub.d/40_custom. If something goes wrong, you can get back the original file.

Line 2, back up the startup menu / boot/grub2/grub.cfg.

Step 3

# vim / etc/grub.d/40_custom

Now that 40_custom has saved a backup, feel free to add content to it, as follows:

Set superusers='root'

Password_pbkdf2 root grub.pbkdf2.sha512.10000.1B34404433526E5002B881AAD026E76B27713C1D26A1471C4907D5A31E86132920D23E5DC8E9DA211A24057CBE9384C158FF2892A26ECEDE790F8C6D3BB2C7BF.55D8820C747338D943E05484E457411F645FD6B7564A903D7CF6780528988AC6C998FB6B7DF67EC559039BC465970C82182D7FA5F36781DDB86FB40F47FE5269

After making changes in the file, press esc to exit, then type: wq and then press enter to exit.

There are only two lines in the above. The backslash after line 2 root is a hyphen. It means that the following content is the same as the previous one.

Step 4

# grub2-mkconfig-o / boot/grub2/grub.cfg

The last command line recompiled the startup menu using the files in the / etc/grub.d directory. The following information is displayed:

Generating grub configuration file...

Found linux image: / boot/vmlinuz-3.10.0-862.el7.x86_64

Found initrd image: / boot/initramfs-3.10.0-862.el7.x86_64.img

Found linux image: / boot/vmlinuz-0-rescue-825a7cb0361a4b7cb98141a640ef42ad

Found initrd image: / boot/initramfs-0-rescue-825a7cb0361a4b7cb98141a640ef42ad.img

Done

# cat / boot/grub2/grub.cfg

As you can see, new content brought in from 40_custom has been added to the new startup menu.

Step 5

# reboot

Restart the system. When displaying the GRUB menu, click in the middle of the window with the mouse, and then press the letter e to modify the startup parameters. "Enter username" (enter your user name) will immediately appear on the screen. Enter root, and you will be prompted for "Enter password" (enter password). Enter the password 123456 and you can see the dark interface that modifies the startup parameters.

At this point, I believe you have a better understanding of "how Linux resets the root password and protects the grub startup menu". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report