1. GRUB2安全概述
GRUB2密码保护是Linux系统安全的重要组成部分,可以防止未授权用户修改启动参数、进入单用户模式或救援模式,从而保护系统免受物理访问攻击。更多学习教程www.fgedu.net.cn
参考Red Hat Enterprise Linux 10官方文档中的System administration章节 from LinuxDBA视频:www.itpux.com
# cat /etc/grub.d/00_header | grep -i password
# 如果没有输出,说明当前没有配置GRUB2密码
# 查看GRUB2用户配置文件
# ls -la /etc/grub.d/00_users
ls: cannot access ‘/etc/grub.d/00_users’: No such file or file does not exist
# 查看当前GRUB2配置中的用户设置
# grep -i “superusers\|password” /boot/grub2/grub.cfg
# 如果没有输出,说明当前没有配置密码保护
2. GRUB2密码生成
GRUB2使用PBKDF2(Password-Based Key Derivation Function 2)算法来加密密码,确保密码存储的安全性。学习交流加群风哥微信: itpux-com
# grub2-mkpasswd-pbkdf2
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF
# 生成多个用户密码
# grub2-mkpasswd-pbkdf2
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF
# 验证密码哈希格式
# echo “grub.pbkdf2.sha512.10000.1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF” | cut -d. -f1-3
grub.pbkdf2.sha512.10000
3. 超级用户配置
GRUB2超级用户(superusers)具有最高权限,可以执行所有GRUB2命令,包括编辑启动项、进入救援模式等。学习交流加群风哥QQ113257174
# vi /etc/grub.d/00_users
# 添加以下内容 # 添加多个超级用户 GRUB2可以为特定的启动菜单项设置密码保护,限制未授权用户访问敏感的启动选项。 # 编辑/etc/grub.d/10_linux文件,为特定菜单项添加密码保护 # 在menuentry行之前添加–unrestricted或–users参数 # 在所有menuentry行添加–unrestricted参数 # 或者,为特定用户设置访问权限 # 添加自定义菜单项并设置用户权限 配置GRUB2密码后,需要验证配置是否正确生效,确保密码保护能够正常工作。 # 验证密码哈希 # 验证菜单项保护 # 测试GRUB2配置 # 在GRUB2启动菜单中: # 尝试访问受保护的菜单项 # 验证未授权访问被拒绝 如果忘记GRUB2密码或密码配置错误导致无法启动系统,可以通过救援模式恢复或重置密码。 # 备份原始配置 # 重新生成GRUB2用户配置文件 # 添加新的超级用户配置 # 删除GRUB2用户配置文件 # 重新生成GRUB2配置 # 退出chroot环境 # 重启系统 # 方法3:使用Live CD重置密码 # 切换到原系统 # 按照方法1或方法2重置密码
在生产环境中,GRUB2密码保护应该遵循安全最佳实践,确保系统安全性和可管理性的平衡。 # 2. 配置多个超级用户 GRUB2的审计和日志记录可以帮助管理员跟踪启动配置的更改,及时发现潜在的安全问题。 # 发送告警邮件 # 保存当前哈希 # 添加执行权限 # 在GRUB2配置更新后执行 # 查看审计日志 # 3. 定期检查GRUB2配置完整性 GRUB2密码配置可能出现各种问题,需要掌握基本的故障排查方法。 更多视频教程www.fgedu.net.cn # 排查步骤: # 2. 检查超级用户配置 # 3. 验证配置文件语法 # 4. 如果配置错误,使用救援模式重置密码 # 问题2:密码保护未生效 # 排查步骤: # 2. 检查是否配置了密码 # 3. 检查菜单项是否设置了–users参数 # 4. 检查配置文件是否正确生成 # 排查步骤: # 2. 如果菜单项设置了–users参数,确保当前用户有权限 # 3. 如果需要,添加–unrestricted参数使菜单项对所有用户可见 # 问题4:密码哈希生成失败 # 排查步骤: # 2. 重新安装grub2-tools # 3. 确保输入密码时没有特殊字符问题 # 4. 检查系统locale设置 在生产环境中部署GRUB2密码保护需要综合考虑安全性、可管理性和系统可用性。 # 检查4:配置文件语法 # 检查5:启动超时设置 # 检查6:内核参数配置 # 检查7:菜单项保护 # 检查8:配置文件备份 # 检查9:审计配置 # 检查10:密码强度 echo “” if [ $SECURITY_SCORE -ge 8 ]; then # 添加执行权限 # 执行安全检查 本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
cat <
# vi /etc/grub.d/00_users
cat <4. 启动菜单项保护
# grep “^menuentry” /boot/grub2/grub.cfg | cut -d “‘” -f2
Red Hat Enterprise Linux (5.14.0-123.el10.x86_64) 10
Red Hat Enterprise Linux (5.14.0-122.el10.x86_64) 10
Red Hat Enterprise Linux (0-rescue-1234567890abcdef1234567890abcdef) 10
# vi /etc/grub.d/10_linux
# 例如,为救援模式添加密码保护
cat <<'EOF'
menuentry 'Red Hat Enterprise Linux (0-rescue-1234567890abcdef1234567890abcdef) 10' --users=root {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
echo 'Loading kernel ...'
linux /vmlinuz-0-rescue-1234567890abcdef1234567890abcdef root=/dev/mapper/rhel-root ro rd.break
echo 'Loading initial ramdisk ...'
initrd /initramfs-0-rescue-1234567890abcdef1234567890abcdef.img
}
EOF
# 重新生成GRUB2配置
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.14.0-123.el10.x86_64
Found initrd image: /boot/initramfs-5.14.0-123.el10.x86_64.img
Found linux image: /boot/vmlinuz-5.14.0-122.el10.x86_64
Found initrd image: /boot/initramfs-5.14.0-122.el10.x86_64.img
done
# 验证菜单项保护
# grep -A 1 "rescue" /boot/grub2/grub.cfg | grep menuentry
menuentry 'Red Hat Enterprise Linux (0-rescue-1234567890abcdef1234567890abcdef) 10' --users=root
# 编辑/etc/grub.d/10_linux
# vi /etc/grub.d/10_linux
# 这样所有菜单项都需要密码才能访问
# 编辑/etc/grub.d/40_custom
# vi /etc/grub.d/40_custom
cat <<'EOF'
menuentry 'Custom Rescue Mode' --users=root {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
echo 'Loading kernel ...'
linux /vmlinuz-5.14.0-123.el10.x86_64 root=/dev/mapper/rhel-root ro rd.break
echo 'Loading initial ramdisk ...'
initrd /initramfs-5.14.0-123.el10.x86_64.img
}
menuentry 'Debug Mode' --users=admin {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
echo 'Loading kernel ...'
linux /vmlinuz-5.14.0-123.el10.x86_64 root=/dev/mapper/rhel-root ro debug
echo 'Loading initial ramdisk ...'
initrd /initramfs-5.14.0-123.el10.x86_64.img
}
EOF
# 重新生成GRUB2配置
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.14.0-123.el10.x86_64
Found initrd image: /boot/initramfs-5.14.0-123.el10.x86_64.img
Found linux image: /boot/vmlinuz-5.14.0-122.el10.x86_64
Found initrd image: /boot/initramfs-5.14.0-122.el10.x86_64.img
done
5. 密码配置验证
# grep “set superusers” /boot/grub2/grub.cfg
set superusers=”root admin”
# grep “password_pbkdf2” /boot/grub2/grub.cfg
password_pbkdf2 root grub.pbkdf2.sha512.10000.1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF
password_pbkdf2 admin grub.pbkdf2.sha512.10000.ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF
# grep “menuentry.*–users” /boot/grub2/grub.cfg
menuentry ‘Red Hat Enterprise Linux (0-rescue-1234567890abcdef1234567890abcdef) 10’ –users=root
menuentry ‘Custom Rescue Mode’ –users=root
menuentry ‘Debug Mode’ –users=admin
# grub2-fstest /boot/grub2/grub.cfg
Configuration file is valid
# reboot
# 1. 尝试编辑启动项(按e键)
# 2. 系统会提示输入用户名和密码
# 3. 输入正确的用户名和密码后才能编辑
# 1. 选择受保护的菜单项
# 2. 系统会提示输入用户名和密码
# 3. 只有授权用户才能启动该菜单项
# 1. 尝试输入错误的密码
# 2. 系统会拒绝访问并返回菜单
6. 密码恢复与重置
# 1. 使用RHEL 10安装介质启动
# 2. 在启动菜单中选择”Troubleshooting” -> “Rescue a Red Hat Enterprise Linux system”
# 3. 选择”1) Continue”挂载原系统
# 4. 切换到原系统的根目录
# chroot /mnt/sysimage
# cp /etc/grub.d/00_users /etc/grub.d/00_users.backup
# vi /etc/grub.d/00_users
cat <
# 使用救援模式挂载系统
# chroot /mnt/sysimage
# rm -f /etc/grub.d/00_users
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file …
Found linux image: /boot/vmlinuz-5.14.0-123.el10.x86_64
Found initrd image: /boot/initramfs-5.14.0-123.el10.x86_64.img
done
# exit
# reboot
# 1. 使用Live CD启动系统
# 2. 挂载原系统根分区
# mkdir /mnt/rhel
# mount /dev/mapper/rhel-root /mnt/rhel
# chroot /mnt/rhel7. 安全最佳实践
# 密码要求:
# – 至少12个字符
# – 包含大小写字母、数字和特殊字符
# – 不包含字典词汇或个人信息
# – 定期更换(建议每90天)
# vi /etc/grub.d/00_users
cat <
# 创建密码轮换脚本
# cat > /fgedu/shell/rotate_grub_password.sh << 'EOF'
#!/bin/bash
# GRUB2密码轮换脚本
# from:www.itpux.com.qq113257174.wx:itpux-com
# 生成新密码
NEW_PASSWORD=$(openssl rand -base64 16)
NEW_HASH=$(echo -e "$NEW_PASSWORD\n$NEW_PASSWORD" | grub2-mkpasswd-pbkdf2 | tail -1 | cut -d' ' -f7)
# 备份当前配置
cp /etc/grub.d/00_users /etc/grub.d/00_users.backup.$(date +%Y%m%d)
# 更新密码
sed -i "s/password_pbkdf2 root .*/password_pbkdf2 root $NEW_HASH/" /etc/grub.d/00_users
# 重新生成GRUB2配置
grub2-mkconfig -o /boot/grub2/grub.cfg
# 记录新密码(实际生产中应该使用密码管理器)
echo "New GRUB2 password: $NEW_PASSWORD" | mail -s "GRUB2 Password Rotated" admin@fgedu.net.cn
echo "GRUB2 password rotated successfully"
EOF
# 添加执行权限
# chmod +x /fgedu/shell/rotate_grub_password.sh
# 定期轮换密码(每90天)
# echo "0 3 1 */3 * /fgedu/shell/rotate_grub_password.sh >> /var/log/grub_password.log 2>&1″ >> /etc/crontab
8. 审计与日志记录
# 创建日志记录脚本
# cat > /fgedu/shell/log_grub_changes.sh << 'EOF'
#!/bin/bash
# GRUB2配置更改日志记录
# from:www.itpux.com.qq113257174.wx:itpux-com
LOG_FILE="/var/log/grub_changes.log"
CONFIG_FILE="/boot/grub2/grub.cfg"
# 获取当前配置的MD5哈希
CURRENT_HASH=$(md5sum $CONFIG_FILE | cut -d' ' -f1)
# 检查是否存在之前的哈希记录
if [ -f /var/tmp/grub_config_hash ]; then
PREVIOUS_HASH=$(cat /var/tmp/grub_config_hash)
# 比较哈希值
if [ "$CURRENT_HASH" != "$PREVIOUS_HASH" ]; then
echo "[$(date)] GRUB2 configuration changed" >> $LOG_FILE
echo “Previous hash: $PREVIOUS_HASH” >> $LOG_FILE
echo “Current hash: $CURRENT_HASH” >> $LOG_FILE
echo “Changed by: $(whoami)” >> $LOG_FILE
echo “” >> $LOG_FILE
echo “GRUB2 configuration has been changed. Please review the changes.” | \
mail -s “GRUB2 Configuration Changed” admin@fgedu.net.cn
fi
fi
echo $CURRENT_HASH > /var/tmp/grub_config_hash
EOF
# chmod +x /fgedu/shell/log_grub_changes.sh
# echo “/fgedu/shell/log_grub_changes.sh” >> /etc/grub.d/99_logging
# chmod +x /etc/grub.d/99_logging
# 使用auditd监控配置文件
# auditctl -w /etc/grub.d/00_users -p wa -k grub_config
# auditctl -w /etc/default/grub -p wa -k grub_config
# auditctl -w /boot/grub2/grub.cfg -p wa -k grub_config
# ausearch -k grub_config -ts recent
—-
time->Wed Apr 2 10:00:00 2026
type=PATH msg=audit(1234567890.123:123): item=0 name=”/etc/grub.d/00_users” inode=123456 dev=08:01 mode=0100600 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:etc_t:s0 nametype=NORMAL
type=CWD msg=audit(1234567890.123:123): cwd=”/root”
type=SYSCALL msg=audit(1234567890.123:123): arch=c000003e syscall=2 success=yes exit=3 a0=7fffd1234567 a1=241 a2=180 a3=0 items=1 ppid=1234 pid=12345 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=123 comm=”vi” exe=”/usr/bin/vi” key=”grub_config”
# 创建完整性检查脚本
# cat > /fgedu/shell/check_grub_integrity.sh << 'EOF'
#!/bin/bash
# GRUB2配置完整性检查
# from:www.itpux.com.qq113257174.wx:itpux-com
echo "=== GRUB2 Integrity Check ==="
echo "Date: $(date)"
echo ""
# 检查配置文件是否存在
if [ ! -f /boot/grub2/grub.cfg ]; then
echo "ERROR: GRUB2 configuration file not found"
exit 1
fi
# 检查配置文件语法
if ! grub2-fstest /boot/grub2/grub.cfg; then
echo "ERROR: GRUB2 configuration file is invalid"
exit 1
fi
# 检查超级用户配置
if ! grep -q "set superusers" /boot/grub2/grub.cfg; then
echo "WARNING: No superusers configured"
fi
# 检查密码配置
if ! grep -q "password_pbkdf2" /boot/grub2/grub.cfg; then
echo "WARNING: No passwords configured"
fi
echo "=== Check Complete ==="
EOF
# 添加执行权限
# chmod +x /fgedu/shell/check_grub_integrity.sh
# 定期执行检查
# echo "0 4 * * * /fgedu/shell/check_grub_integrity.sh >> /var/log/grub_integrity.log 2>&1″ >> /etc/crontab
9. 故障排查
# 症状:系统启动时提示输入密码,但输入正确密码后仍无法启动
# 1. 检查密码哈希格式是否正确
# grep “password_pbkdf2” /boot/grub2/grub.cfg
# 确保格式为:grub.pbkdf2.sha512.10000.
# grep “set superusers” /boot/grub2/grub.cfg
# 确保超级用户名称与密码哈希中的用户名称一致
# grub2-fstest /boot/grub2/grub.cfg
# 参见”密码恢复与重置”部分
# 症状:可以编辑启动项或访问受保护菜单项而不需要密码
# 1. 检查是否配置了超级用户
# grep “set superusers” /boot/grub2/grub.cfg
# grep “password_pbkdf2” /boot/grub2/grub.cfg
# grep “menuentry.*–users” /boot/grub2/grub.cfg
# ls -la /etc/grub.d/00_users
# chmod 755 /etc/grub.d/00_users
# grub2-mkconfig -o /boot/grub2/grub.cfg
# 症状:配置密码后,某些启动菜单项不再显示
# 1. 检查菜单项权限设置
# grep “menuentry” /boot/grub2/grub.cfg | head -5
# 检查当前登录用户是否在超级用户列表中
# 编辑/etc/grub.d/10_linux,在menuentry行添加–unrestricted
# 症状:grub2-mkpasswd-pbkdf2命令失败或输出格式不正确
# 1. 检查grub2-tools是否正确安装
# rpm -qa | grep grub2-tools
# dnf reinstall grub2-tools
# 使用简单的密码测试
# echo $LANG
# export LANG=en_US.UTF-8
10. 生产环境部署
# cat > /fgedu/shell/secure_grub.sh << 'EOF'
#!/bin/bash
# GRUB2生产环境安全配置脚本
# from:www.itpux.com.qq113257174.wx:itpux-com
echo "=== GRUB2 Security Configuration ==="
echo "Date: $(date)"
echo ""
# 1. 备份原始配置
echo "1. Backing up original configuration..."
cp /etc/default/grub /etc/default/grub.backup.$(date +%Y%m%d)
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.backup.$(date +%Y%m%d)
# 2. 生成强密码
echo "2. Generating strong passwords..."
ROOT_PASSWORD=$(openssl rand -base64 24)
ADMIN_PASSWORD=$(openssl rand -base64 24)
# 生成密码哈希
ROOT_HASH=$(echo -e "$ROOT_PASSWORD\n$ROOT_PASSWORD" | grub2-mkpasswd-pbkdf2 | tail -1 | cut -d' ' -f7)
ADMIN_HASH=$(echo -e "$ADMIN_PASSWORD\n$ADMIN_PASSWORD" | grub2-mkpasswd-pbkdf2 | tail -1 | cut -d' ' -f7)
# 3. 创建用户配置文件
echo "3. Creating user configuration..."
cat > /etc/grub.d/00_users << USEREOF
set superusers="root admin"
password_pbkdf2 root $ROOT_HASH
password_pbkdf2 admin $ADMIN_HASH
USEREOF
chmod 600 /etc/grub.d/00_users
# 4. 配置启动超时
echo "4. Configuring boot timeout..."
sed -i 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=5/' /etc/default/grub
# 5. 配置内核参数
echo "5. Configuring kernel parameters..."
sed -i 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rhel\/root rd.lvm.lv=rhel\/swap rhgb quiet transparent_hugepage=never numa=off"/' /etc/default/grub
# 6. 重新生成GRUB2配置
echo "6. Regenerating GRUB2 configuration..."
grub2-mkconfig -o /boot/grub2/grub.cfg
# 7. 验证配置
echo "7. Verifying configuration..."
if grub2-fstest /boot/grub2/grub.cfg; then
echo "Configuration is valid"
else
echo "ERROR: Configuration is invalid"
exit 1
fi
# 8. 保存密码到安全位置
echo "8. Saving passwords to secure location..."
mkdir -p /root/.grub_secrets
chmod 700 /root/.grub_secrets
cat > /root/.grub_secrets/passwords.txt << PWDEOF
GRUB2 Passwords - Generated on $(date)
========================================
Root user password: $ROOT_PASSWORD
Admin user password: $ADMIN_PASSWORD
========================================
IMPORTANT: Store these passwords securely!
PWDEOF
chmod 600 /root/.grub_secrets/passwords.txt
# 9. 发送密码到管理员邮箱
echo "9. Sending passwords to administrator..."
cat /root/.grub_secrets/passwords.txt | mail -s "GRUB2 Passwords for $(hostname)" admin@fgedu.net.cn
echo ""
echo "=== Configuration Complete ==="
echo "Passwords have been saved to /root/.grub_secrets/passwords.txt"
echo "Please store these passwords securely!"
echo ""
echo "IMPORTANT: After verifying the configuration works correctly,"
echo "delete the password file: rm /root/.grub_secrets/passwords.txt"
EOF
# 添加执行权限
# chmod +x /fgedu/shell/secure_grub.sh
# 执行配置脚本
# /fgedu/shell/secure_grub.sh
# cat > /fgedu/shell/check_grub_security.sh << 'EOF'
#!/bin/bash
# GRUB2安全检查脚本
# from:www.itpux.com.qq113257174.wx:itpux-com
echo "=== GRUB2 Security Check ==="
echo "Date: $(date)"
echo ""
SECURITY_SCORE=0
MAX_SCORE=10
# 检查1:超级用户配置
echo "Check 1: Superuser configuration"
if grep -q "set superusers" /boot/grub2/grub.cfg; then
echo " PASS: Superusers configured"
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo " FAIL: No superusers configured"
fi
# 检查2:密码配置
echo "Check 2: Password configuration"
if grep -q "password_pbkdf2" /boot/grub2/grub.cfg; then
echo " PASS: Passwords configured"
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo " FAIL: No passwords configured"
fi
# 检查3:配置文件权限
echo "Check 3: Configuration file permissions"
if [ $(stat -c %a /etc/grub.d/00_users 2>/dev/null) = “600” ]; then
echo ” PASS: File permissions are secure”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo ” FAIL: File permissions are not secure”
fi
echo “Check 4: Configuration file syntax”
if grub2-fstest /boot/grub2/grub.cfg; then
echo ” PASS: Configuration file is valid”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo ” FAIL: Configuration file is invalid”
fi
echo “Check 5: Boot timeout setting”
TIMEOUT=$(grep “^set timeout” /boot/grub2/grub.cfg | cut -d’ ‘ -f2)
if [ “$TIMEOUT” -le 10 ] && [ “$TIMEOUT” -ge 3 ]; then
echo ” PASS: Boot timeout is appropriate ($TIMEOUT seconds)”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo ” WARN: Boot timeout may need adjustment ($TIMEOUT seconds)”
fi
echo “Check 6: Kernel parameters”
if grep -q “transparent_hugepage=never” /boot/grub2/grub.cfg; then
echo ” PASS: Kernel parameters are optimized”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo ” INFO: Consider adding kernel parameters”
fi
echo “Check 7: Menu entry protection”
PROTECTED_ENTRIES=$(grep “menuentry.*–users” /boot/grub2/grub.cfg | wc -l)
if [ “$PROTECTED_ENTRIES” -gt 0 ]; then
echo ” PASS: $PROTECTED_ENTRIES menu entries are protected”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo ” INFO: Consider protecting sensitive menu entries”
fi
echo “Check 8: Configuration file backup”
if [ -f /boot/grub2/grub.cfg.backup.* ]; then
echo ” PASS: Configuration backup exists”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo ” WARN: No configuration backup found”
fi
echo “Check 9: Audit configuration”
if auditctl -l | grep -q “grub_config”; then
echo ” PASS: Audit rules are configured”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
else
echo ” INFO: Consider configuring audit rules”
fi
echo “Check 10: Password strength”
# 这里可以添加密码强度检查逻辑
echo ” INFO: Manual password strength review recommended”
SECURITY_SCORE=$((SECURITY_SCORE + 1))
echo “=== Security Score: $SECURITY_SCORE/$MAX_SCORE ===”
echo “Overall: EXCELLENT”
exit 0
elif [ $SECURITY_SCORE -ge 6 ]; then
echo “Overall: GOOD”
exit 0
elif [ $SECURITY_SCORE -ge 4 ]; then
echo “Overall: FAIR”
exit 1
else
echo “Overall: POOR”
exit 2
fi
EOF
# chmod +x /fgedu/shell/check_grub_security.sh
# /fgedu/shell/check_grub_security.sh
