CentOS 7 set grub password and single user login example code

CentOS 7 set grub password and single user login example code

There are significant differences between centos7 and centos6 in the steps of setting the grub password. This is recorded for future reference.

The purpose of grub encryption: to prevent criminals from modifying the root password in single-user mode

You can use plain text or encrypted ciphertext to encrypt grub. It is recommended to use the encrypted ciphertext method. The operation steps of the two methods are similar. This article takes the encrypted ciphertext method as an example.

1. Set up grub encryption

1. Use the grub2-mkpasswd-pbkdf2 command to create a ciphertext (be sure to save and remember the password you set)

2. At the end of the /etc/grub.d/00_header file, add the following content (root is the user name used for single-user login, and the third line after root is the ciphertext obtained after encryption in the previous step. Note that there is a space between root and the ciphertext, not a line break)

cat <<EOF
set superusers='root'
password_pbkdf2 root grub.pbkdf2.sha512.10000.B157F42E96462AB239C03000F113D32EB18FD48073F1FC7D8F87A8F3B3F89F662424ECCAB901F3A812A997E547FD520F3E99D0E080F4FE8B05E019757E34F75B.29C83F87B4B6C086FC9A81E046CC3623CC5CF2F82128EDC3A0364894E429D4993B28563F82D71BF346188108CBD4341FC4A71B90E543581646B4E7EAE920C54A
E0F

3. Recompile and generate grub.cfg file

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

The setup is complete.

2. Restart and use single user login test

1. Reboot to enter gurb interface

2. Press e

3. At this time, we need to enter the username and password we set to enter grub (seeing this interface means that we have set grub encryption to take effect). After entering correctly, you will enter the following interface

4. Edit and modify two places: change ro to rw, and add init=/bin/sh at the end of the line

5.ctrl+x starts single-user mode and enters the system

6. Change the root password

7. If selinux is turned on, you need to execute the following command to update the system information, otherwise the password will not take effect after restarting

touch /.autorelabel

8. Restart the system

exec /sbin/init

Login successfully using the modified root password.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to quickly modify the root password under CentOS8
  • How to change the password of mysql5.7.20 under linux CentOS 7.4
  • How to reset the root password in CentOS7
  • How to modify the root password of MySQL in CentOS environment
  • Solution to the problem of still having to enter a password after configuring ssh password-free login in centos
  • How to install and modify the initial password of mysql5.7.18 under Centos7.3
  • How to change mysql password under Centos
  • CentOS 7 Forgot Password Solution Process Diagram

<<:  js to achieve simple magnifying glass effects

>>:  Python MySQL database table modification and query

Recommend

Introduction to several ways to introduce CSS in HTML

Table of contents 1. Embed CSS styles directly in...

Detailed explanation of mixed inheritance in Vue

Table of contents The effect of mixed inheritance...

How to use Vue3 asynchronous data loading component suspense

Table of contents Preface Creating Components Sum...

Detailed explanation of downloading, installing and using nginx server

download http://nginx.org/en/download.html Unzip ...

How to build an ELK log system based on Docker

Background requirements: As the business grows la...

Use Vue3 to implement a component that can be called with js

Table of contents Preface 1. Conventional Vue com...

Detailed explanation of the usage and differences of MySQL views and indexes

MySQL Views Simply put, a MySQL view is a shortcu...

Basic learning tutorial of table tag in HTML

Table label composition The table in HTML is comp...

I have compiled a few cool design sites that I think are good.

You must have inspiration to design a website. Goo...

Why is it not recommended to use an empty string as a className in Vue?

Table of contents Compare the empty string '&...

Detailed example of Linux all-round system monitoring tool dstat

All-round system monitoring tool dstat dstat is a...

Docker View the Mount Directory Operation of the Container

Only display Docker container mount directory inf...

The difference and usage of distinct and row_number() over() in SQL

1 Introduction When we write SQL statements to op...