when the root password is accidentally forgotten, we can change the root password by entering single-user mode, in order to prevent others from entering the single-user mode to change the password, we can also encrypt the grub file, improve security, to enter the single-user mode must enter a password to go in.
1. Change the root password
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/83/DD/wKiom1d-TLrBrii8AAAXAekh1XM925.png-wh_500x0-wm_3 -wmp_4-s_326427376.png "title=" 02.png "alt=" Wkiom1d-tlrbrii8aaaxaekh1xm925.png-wh_50 "/>
When the system boots to this interface, press any key to enter the hidden menu
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/83/DD/wKiom1d-TRmQerqNAAAnjYWt2RE741.png-wh_500x0-wm_3 -wmp_4-s_4134891950.png "title=" 01.png "alt=" Wkiom1d-trmqerqnaaanjywt2re741.png-wh_50 "/>
To enter this menu, press the A key,
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/83/DC/wKioL1d-TYGx2K88AAAigc0In2U171.png-wh_500x0-wm_3 -wmp_4-s_3614828806.png "title=" 03.png "alt=" Wkiol1d-tygx2k88aaaigc0in2u171.png-wh_50 "/>
Press a key to enter this interface, enter 1 in the back, enter the single user mode, single user mode does not require a password to enter the system directly
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/83/DD/wKiom1d-TfjBRd_2AAAU6PD2Ua4306.png-wh_500x0-wm_3 -wmp_4-s_2191288899.png "title=" 04.png "alt=" Wkiom1d-tfjbrd_2aaau6pd2ua4306.png-wh_50 "/>
After entering this interface, you can change the root password, then reboot, and the password will be changed to complete.
2, encrypted grub file, after the Grub file encryption, only know the password to enter the menu
[[email protected] ~]# vim/boot/grub/grub.conf Open Grub configuration file
default=0
Timeout=5
Splashimage= (hd0,0)/grub/splash.xpm.gz
Hiddenmenu
Password--MD5 $1$xwsxo$lamn4y9gyz7gvu/lrsghl/This column is the encryption grub
Title CentOS 6 (2.6.32-573.el6.x86_64)
Root (hd0,0)
kernel/vmlinuz-2.6.32-573.el6.x86_64 ro root=uuid=ca248f95-07df-4836-a807-e0150c5749c7 Rd_NO_LUKS rd_NO_LVM LANG=en _us. UTF-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto keyboardtype=pc keytable=us Rd_NO_DM rhgb quiet
Initrd/initramfs-2.6.32-573.el6.x86_64.img
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/DD/wKioL1d-Uc2iQlDCAAAtzdbsW64557.png-wh_500x0-wm_3 -wmp_4-s_3440124708.png "title=" 05.png "alt=" Wkiol1d-uc2iqldcaaatzdbsw64557.png-wh_50 "/>
after rebooting the system, press any key, you can not go directly to the menu editing mode, you need to enter the password, to be able to enter the editing mode, if there is no password, directly enter, you will be able to directly start the system.
3, destroy the first two stages of system startup, by repairing grub to enable the system to start up
[[email protected] ~]# dd If=/dev/zero OF=/DEV/SDA bs=446 count=1
1+0 Records in
1+0 Records out
446 bytes (446 B) copied, 0.0131584 s, 33.9 kb/s
destroys the first 446 bytes of the SDA disk by using the DD command, and then restarts
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/83/DE/wKiom1d-V4vib-IhAAAiQIH4dOQ490.png-wh_500x0-wm_3 -wmp_4-s_2595668496.png "title=" 06.png "alt=" Wkiom1d-v4vib-ihaaaiqih4doq490.png-wh_50 "/>
After rebooting, you will not be able to enter the system, you can enter rescue mode to repair
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/83/DE/wKiom1d-WGyixXROAAWDyXP1CFM860.png-wh_500x0-wm_3 -wmp_4-s_1736154518.png "title=" 07.png "alt=" Wkiom1d-wgyixxroaawdyxp1cfm860.png-wh_50 "/>
Enter this interface, move the cursor down, move to the third item, Rescue, and then enter
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/83/DD/wKioL1d-WOKwkRc8AAA6zDEsTQE765.png-wh_500x0-wm_3 -wmp_4-s_1561655507.png "title=" 08.png "alt=" Wkiol1d-wokwkrc8aaa6zdestqe765.png-wh_50 "/>
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/83/DE/wKiom1d-WQXDX_vGAAA4WArWpNg421.png-wh_500x0-wm_3 -wmp_4-s_1178522927.png "title=" 09.png "alt=" Wkiom1d-wqxdx_vgaaa4warwpng421.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/83/DE/wKiom1d-WS-zndBzAAAqOl2Z_6c601.png-wh_500x0-wm_3 -wmp_4-s_324881825.png "title=" 10.png "alt=" Wkiom1d-ws-zndbzaaaqol2z_6c601.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/83/DD/wKioL1d-WVfTLK8LAAAnnoJT4c8951.png-wh_500x0-wm_3 -wmp_4-s_281772178.png "title=" 11.png "alt=" Wkiol1d-wvftlk8laaannojt4c8951.png-wh_50 "/>
In this interface, the system can be repaired by switching to the root directory with the command chroot, repairing the SDA disk with the GRUB command, then exit, returning to the previous level, and restarting the system.
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/83/DD/wKioL1d-Wf7iYLBvAAAiHYSs4FU460.png-wh_500x0-wm_3 -wmp_4-s_1565057301.png "title=" 12.png "alt=" Wkiol1d-wf7iylbvaaaihyss4fu460.png-wh_50 "/>
4, delete/boot directory and/etc/fstab, through the disc rescue mode can repair the system
[Email protected] ~]# rm-rf/boot/*
[Email protected] ~]# Rm-rf/etc/fstab
[email protected] ~]# reboot
The system will not start with some of the above actions
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/83/DE/wKioL1d-bciBt5idAAAXyZd2Oco693.png-wh_500x0-wm_3 -wmp_4-s_2755065882.png "title=" 01.png "alt=" Wkiol1d-bcibt5idaaaxyzd2oco693.png-wh_50 "/>
Restart will prompt for the above error
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/83/DF/wKiom1d-bj7y4TB1AAAs5jplMO8812.png-wh_500x0-wm_3 -wmp_4-s_3331243984.png "title=" 04.png "alt=" Wkiom1d-bj7y4tb1aaas5jplmo8812.png-wh_50 "/>
Start again, press ESC on this interface
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/83/DF/wKiom1d-bw-gUleqAAAX2EgCyEI678.png-wh_500x0-wm_3 -wmp_4-s_1926739644.png "title=" 03.png "alt=" Wkiom1d-bw-guleqaaax2egcyei678.png-wh_50 "/>
Enter this interface, select CD entry, boot from CD
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/83/DF/wKiom1d-b2uQ3ilAAAUn8msSdfg178.png-wh_500x0-wm_3 -wmp_4-s_3694895409.png "title=" 05.png "alt=" Wkiom1d-b2uq3ilaaaun8mssdfg178.png-wh_50 "/>
Enter the above interface, select the third entry, enter the rescue mode
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/83/DF/wKiom1d-cBSj1-qPAAAqeTwitjM218.png-wh_500x0-wm_3 -wmp_4-s_1250735726.png "style=" Float:none; "title=" 06.png "alt=" Wkiom1d-cbsj1-qpaaaqetwitjm218.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/83/DE/wKioL1d-cBST9QznAAAjITrsKQI808.png-wh_500x0-wm_3 -wmp_4-s_1516320641.png "style=" Float:none; "title=" 07.png "alt=" Wkiol1d-cbst9qznaaajitrskqi808.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/DE/wKioL1d-cBXzs-x7AABGUwf1tMk260.png-wh_500x0-wm_3 -wmp_4-s_3062487865.png "style=" Float:none; "title=" 09.png "alt=" Wkiol1d-cbxzs-x7aabguwf1tmk260.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/DF/wKiom1d-cBXCR6xPAAAcYIYfBMI852.png-wh_500x0-wm_3 -wmp_4-s_3169786254.png "style=" Float:none; "title=" 10.png "alt=" Wkiom1d-cbxcr6xpaaacyiyfbmi852.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/DE/wKioL1d-cBbwNFoOAAAV27TjsKo192.png-wh_500x0-wm_3 -wmp_4-s_1408382342.png "style=" Float:none; "title=" 11.png "alt=" Wkiol1d-cbbwnfooaaav27tjsko192.png-wh_50 "/>
Enter the following interface, chroot/mnt/sysimage/, is not the past, the disk configuration file is deleted, the root directory cannot be automatically mounted, you can use the Fdisk command to view the disk partition, SDA2 is the root directory, SDA1 is the boot directory
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/83/DF/wKiom1d-cS_APUtGAABQs_H7SsE773.png-wh_500x0-wm_3 -wmp_4-s_4024918569.png "title=" 12.png "alt=" Wkiom1d-cs_aputgaabqs_h7sse773.png-wh_50 "/>
Hang the root directory with the Mount command, then use the chroot command to cut to the root, write the disk configuration file again, and then restart it to mount it automatically. Repeat the above steps before entering into rescue mode.
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/83/DF/wKiom1d-cnySUz9JAAAigKy6BpA682.png-wh_500x0-wm_3 -wmp_4-s_1907475449.png "title=" 13.png "alt=" Wkiom1d-cnysuz9jaaaigky6bpa682.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/DE/wKioL1d-csbyIbN1AAAPzMrvKFM541.png-wh_500x0-wm_3 -wmp_4-s_2538398637.png "title=" 14.png "alt=" Wkiol1d-csbyibn1aaapzmrvkfm541.png-wh_50 "/>
After restarting, mount the CD to the media file, reinstall the internal I core, now the boot directory is empty directory, after installing the kernel, the directory will generate kernel and INITRD files. Copy kernel from CD to boot directory It's a bit cumbersome to reinstall the kernel
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/83/DF/wKioL1d-dEiyxJJIAAA6OsAcx4g780.png-wh_500x0-wm_3 -wmp_4-s_1788885357.png "style=" Float:none; "title=" 15.png "alt=" Wkiol1d-deiyxjjiaaa6osacx4g780.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/83/DF/wKiom1d-dL6AU1_TAABJYB-IcgM600.png-wh_500x0-wm_3 -wmp_4-s_1278342135.png "style=" Float:none; "title=" 16.png "alt=" Wkiom1d-dl6au1_taabjyb-icgm600.png-wh_50 "/>
With the kernel, the Grub command is used to generate grub, and the grub configuration file is rewritten, then exit, exit the previous level, reboot the system, and the system can be repaired.
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/83/DF/wKiom1d-dL-zm7TKAAAr6KxY7Iw759.png-wh_500x0-wm_3 -wmp_4-s_1561575766.png "style=" Float:none; "title=" 17.png "alt=" Wkiom1d-dl-zm7tkaaar6kxy7iw759.png-wh_50 "/>
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/83/DF/wKioL1d-dL_x7lzhAAAaxm4St8k173.png-wh_500x0-wm_3 -wmp_4-s_2836645856.png "style=" Float:none; "title=" 18.png "alt=" Wkiol1d-dl_x7lzhaaaaxm4st8k173.png-wh_50 "/>
After the above steps, you can restore the startup file and disk configuration file removal problems, the system started normally.
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/83/DF/wKioL1d-dEmzSrgfAAAaxm4St8k541.png-wh_500x0-wm_3 -wmp_4-s_1127533265.png "style=" Float:none; "title=" 18.png "alt=" Wkiol1d-demzsrgfaaaaxm4st8k541.png-wh_50 "/>
This article is from the "Linux" blog, so be sure to keep this source http://wei2008.blog.51cto.com/11351016/1812469
CentOS-6 system Change Password and system repair