用加密和明文码两种方法为grub配置密码

作者:林惠

来自:linos.vicp.net elinhui.126.com

本文主要是讲述就如何为grub加上密码,也就是为grub上把锁;

grub是操作系统引导程式,类似我们在机器中安装了两个windows出现的选单的管理器os loader ,这样有一个选单让我们选择用哪个操作系统。


#######################################
##方法一:grub 明口令 #########################
#######################################

比如我没有配置密码之前/etc/grub是如下的样子:

default=1     
timeout=10	

splashimage=(hd0,7)/boot/grub/splash.xpm.gz  

title Fedora Core (2.4.22-1.2061.nptl) 
root (hd0,7)

kernel /boot/vmlinuz-2.4.22-1.2061.nptl ro root=LABEL=/

initrd /boot/initrd-2.4.22-1.2061.nptl.img

title WindowsXP

rootnoverify (hd0,0)

chainloader  1

加入以后就是下面这样的:

default=1

timeout=10

splashimage=(hd0,7)/boot/grub/splash.xpm.gz

password=123456

title Fedora Core (2.4.22-1.2061.nptl)

lock

root (hd0,7)

kernel /boot/vmlinuz-2.4.22-1.2061.nptl ro root=LABEL=/

initrd /boot/initrd-2.4.22-1.2061.nptl.img

title WindowsXP

rootnoverify (hd0,0)

chainloader  1

从上面的能够看出,Grub的密码是123456,lock的意思就是把Redhat Fedora锁住了。假如启动时会提示错误。这时就应该按P键,然后输入密码就行了。我配置的是123456,当然应该输入123456了,输入别的密码肯定不能通过,这样是不是做到保密了呢??


#######################################
##方法一:grub 加密口令 ########################
#######################################

经仔细研究得出结论,我又读了一下grub文档,用md5加密校验Grub密码比较安全。为了也能让和我相同菜的弟兄,也能知道如何通过md5进行Grub密码加密,我不得不把这个教程写出来。哈哈,高手就是免读了,此文为菜鸟弟兄所准备。
用md5加密校码Grub密码,这样会更安全。

1]对Grub的密码进行加密码运算,比如我们想配置grub的密码是123456,所以我们先要用md5进行对123456这个密码进行加密

[root@linux01 beinan]# /sbin/grub-md5-crypt

Password: 在这里输入123456

Retype password: 再输入一次123456

uDL20$eSB.XRPG2A2Fv8AeH34nZ0 

uDL20$eSB.XRPG2A2Fv8AeH34nZ0 就是通过grub-md5-crypt进行加密码后产生的值。这个值我们要记下来,还是有点用。
[root@linux01 beinan]#

2]更改 /etc/grub.conf

比如我原来的/etc/grub.conf文档的内容是下面的。

default=1

timeout=10

splashimage=(hd0,7)/boot/grub/splash.xpm.gz

title Fedora Core (2.4.22-1.2061.nptl)

root (hd0,7)

kernel /boot/vmlinuz-2.4.22-1.2061.nptl ro root=LABEL=/

initrd /boot/initrd-2.4.22-1.2061.nptl.img

title WindowsXP

rootnoverify (hd0,0)

chainloader  1

所以我要在/etc/grub.conf中加入 password --md5 uDL20$eSB.XRPG2A2Fv8AeH34nZ0 这行,连同lock,应该加到哪呢,请看我的更改。

timeout=10

splashimage=(hd0,7)/boot/grub/splash.xpm.gz

password --md5 uDL20$eSB.XRPG2A2Fv8AeH34nZ0

title Fedora Core (2.4.22-1.2061.nptl)

lock

root (hd0,7)

kernel /boot/vmlinuz-2.4.22-1.2061.nptl ro root=LABEL=/

initrd /boot/initrd-2.4.22-1.2061.nptl.img

title WindowsXP

rootnoverify (hd0,0)

chainloader  1

我们仔细看一下,从上面的我们改过的/etc/grub.conf中是不是已用到了我们在第一步通过/grub-md5-crypt所产生的密码呢??是不是有点安全感了??