之路 on it Road.com
使用纯文本密码
虽然不安全,但如果我们仍然想设置一个用户可读的纯文本 GRUB 密码,请使用以下过程:
- 在文本编辑器中编辑 /boot/grub/grub.conf 并在第一个标题节之前添加一个新的“password PASSWORD-GOES-HERE”行,例如:
default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu password my-not-so-hidden-password title Red Hat Enterprise Linux ...
- 确保 grub.conf 的权限不允许除 root 之外的任何人读取它:
# chmod 600 /boot/grub/grub.conf # ls -l /boot/grub/grub.conf -rw------- 1 root root 678 Nov 02 14:12 /boot/grub/grub.conf
如何在启动时使用密码保护?
GRUB 引导加载程序将密码存储在纯文本文件中,因此需要任何加密形式的密码。
要生成加密密码,我们可以使用 grub-crypt 命令。
到目前为止,我们一直使用命令 grub-md5-crypt 。
但现在 MD5 被广泛认为已损坏。
grub-crypt 使用被认为更安全的 SHA-256 或者 SHA-512 哈希值。
grub-crypt 命令的一般语法/用法如下所示:
# grub-crypt --help Usage: grub-crypt [OPTION]... Encrypt a password. -h, --help Print this message and exit -v, --version Print the version information and exit --md5 Use MD5 to encrypt the password --sha-256 Use SHA-256 to encrypt the password --sha-512 Use SHA-512 to encrypt the password (default) Report bugs to [bug-grub@gnu.org]. EOF
使用 SHA-265 或者 SHA-512 哈希
- 以root用户身份,使用grub-crypt命令生成密码hash。
输入密码并再次输入密码进行确认。
grub-crypt Password: Retype password: $GXGrYVEnbKXAnQoT$p64OkyclNDt4qM2q47GMsgNxJxQaclNs79gvYYsl4h07ReDtJpt5P5kQn1KQ52u2eW8pKHTqcG50ffv0UlRcW0
- 复制输出的最后一行中返回的加密密码,该密码看起来像一个加扰的长字符串。
将其粘贴在 /boot/grub/grub.conf 文件中的 TITLE 语句之前,如下所示:
# vi /boot/grub/grub.conf .... default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu password --encrypted $GXGrYVEnbKXAnQoT$p64OkyclNDt4qM2q47GMsgNxJxQaclNs79gvYYsl4h07ReDtJpt5P5kQn1KQ52u2eW8pKHTqcG50ffv0UlRcW0 title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64) ....
注意:确保 /boot/grub/grub.conf 文件的权限设置为只读,不允许任何人修改它。
# ls -lrt /boot/grub/grub.conf -rw-------. 1 root root 845 Oct 11 14:43 /boot/grub/grub.conf
- 完成此操作后,在 GRUB 允许我们编辑引导选项之前,将来的引导将需要密码。
使用 MD5 哈希
正如帖子前面所说,MD5 被广泛认为是坏的。
但如果我们仍想使用它们,请按照以下步骤操作:
- 运行 grub-md5-crypt 生成散列密码:
# grub-md5-crypt Password: Retype password: $vweqo$CLFlozZ6ELHjGmL.0.37..
在第一个标题行之前添加一个新的“password -md5 HASH-GOES-HERE”行,例如:
default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu password --md5 $vweqo$CLFlozZ6ELHjGmL.0.37.. title Red Hat Enterprise Linux ...
作为最后的最佳实践步骤,确保 grub.conf 上的权限不允许除 root 之外的任何人读取它:
# chmod 600 /boot/grub/grub.conf # ls -l /boot/grub/grub.conf -rw------- 1 root root 678 Jan 29 18:27 /boot/grub/grub.conf
重新启动系统并尝试按 p 输入密码以解锁并启用 grub 列表中的下一个功能。
日期:2020-09-17 00:11:57 来源:oir作者:oir