Linux systems necessary measures to oblivion taken root password

With an increasing number of companies using the Linux system, Linux system root is a super administrator, administrator Windows equivalent system. It has the absolute authority. When the administrator forget the root password (of course, a very small probability) the necessary measures taken:

Three ways to modify the root password:

First, the first method:

After the boot by "e" on the core: Step 1.

Linux systems necessary measures to oblivion taken root password

Step 2: Move the cursor to the line start linux16 added kernel parameters rd.break, press Ctrl + x start

Linux systems necessary measures to oblivion taken root password

Step 3, followed by executing the following command, restart the system

Linux systems necessary measures to oblivion taken root password

touch /.autorelabel # // If your system does not turn on selinux, you can not do this step

After personally testing, no problem!

Second, the second method:

After the boot by "e" on the core: Step 1.

Linux systems necessary measures to oblivion taken root password

Step 2: Move the cursor to the beginning of the line linux16 instead rw init = / sysroot / bin / sh, press Ctrl + x start

Linux systems necessary measures to oblivion taken root password

Step 3: Enter the following command in order to restart the system

Linux systems necessary measures to oblivion taken root password

touch /.autorelabel # // If your system does not turn on selinux, you can not do this step

After personally testing, no problem!

Third, the third method:

Similar to repair the GRUB boot menu can refer to the blog: Linux fix the MBR and GRUB boot menu
to enter rescue mode input "passwd root" can be!

So easily change the root password is obviously not safe, in order to improve security, we can set the time to enter the GRUB menu, set a password as follows:

[root@localhost ~]# grub2-mkpasswd-pbkdf2                              //根据提示输入密码
输入口令:
Reenter password: 
PBKDF2 hash of your password is 
//“is”之后是经过加密的密码字串符(由于限制,不可发布)
[root@localhost ~]# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
[root@localhost ~]# cp /etc/grub.d/00_header /etc/grub.d/00_header.bak
//建议做个备份(实验环境,无所谓)
[root@localhost ~]# vim /etc/grub.d/00_header                 //这是通过密钥工具生成密码的配置文件
                   ……………………                         //省略部分内容
cat << EOF
set superusers="root"                                      //设置用户名
password_pbkdf2 root                                    
//填写刚才通过密钥工具生成的密钥文件(就是刚才生成密钥文件“is”之后的内容,由于限制不可发布)
//设置用户名的密码 
EOF
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
//重新生成配置文件

Re-test the computer, when you press the "e" key to enter the GRUB menu, you will be prompted:
Linux systems necessary measures to oblivion taken root password
Enter the correct user name and password to enter (the experiment using a root, nothing to do with the system root, but the root file settings and configuration password generation algorithm of encryption)!

Guess you like

Origin blog.51cto.com/14157628/2434526