说明:
平时我们进入系统是可以随便进入GRUB引导界面的。这样就会存在安全隐患。服务器最重要的是安全,只要有人靠近设备就可以破解密码,现在为了防止别人进入单用户模式破解密码,添加grub密码。防止单用户模式修改root密码。
设置密码有三种选择
一、 明文密码
1.修改grub配置文件,在hiddenmenu下一行输入password=123456
[root@localhost ~]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda3
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
password=123456 ##在此添加
title CentOS 6 (2.6.32-642.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=7f16795b-41cb-4435-a881-2f0e6004d1aa rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-642.el6.x86_64.img
二、 设置MD5加密
1.grub-md5-crypt和grub-crypt --md5均可
[root@localhost ~]# grub-md5-crypt
Password: ##密码是123456
Retype password:
$1$QwrJp/$iWaHMypNHSM.xW70gWR41/
2.修改grub配置文件,在hiddenmenu下一行输入
password --md5 $1$QwrJp/$iWaHMypNHSM.xW70gWR41/

三、设置sha加密密码
1. 使用grub-crypt --sha-256 设置sha密码加密命令
[root@localhost ~]# grub-crypt --sha-256
Password:
Retype password:
$5$OV.hJvh.GwALljZr$YgZiaSxaglm23wzAbJzjFc2iPp2q1yNqlxM5EYPqz70
2.修改grub配置文件,在hiddenmenu下一行输入
password --encrypted $5$OV.hJvh.GwALljZr$YgZiaSxaglm23wzAbJzjFc2iPp2q1yNqlxM5EYPqz70

三、 验证
之前可以按e键直接进入如下图

添加密码之后如下图

按p键之后输入密码

之后就可以进入grub

网友评论