如何用密码保护Ubuntu的Boot Loader

Ubuntu’s Grub boot loader lets anyone edit boot entries or use its command-line mode by default. Secure Grub with a password and no one can edit them — you can even require a password before booting operating systems.

默认情况下,Ubuntu的Grub引导加载程序允许任何人编辑引导条目或使用其命令行模式。 使用密码保护Secure Grub,没有人可以编辑它们-您甚至可以在启动操作系统之前要求输入密码。

Grub 2’s configuration options are split across multiple files instead of the single menu.lst file Grub 1 used, so setting a password has become more complicated. These steps apply to Grub 1.99, used in Ubuntu 11.10. The process may be different in future versions.

Grub 2的配置选项被拆分为多个文件,而不是单个menu.lst文件。Grub1被使用,因此设置密码变得更加复杂。 这些步骤适用于在Ubuntu 11.10中使用的Grub 1.99。 在将来的版本中,该过程可能会有所不同。

生成密码哈希 (Generating a Password Hash)

First, we’ll fire up a terminal from Ubuntu’s applications menu.

首先,我们将从Ubuntu的应用程序菜单中启动一个终端。

Now we’ll generate an obfuscated password for Grub’s configuration files. Just type grub-mkpasswd-pbkdf2 and press Enter. It’ll prompt you for a password and give you a long string. Select the string with your mouse, right-click it and select Copy to copy it to your clipboard for later.

现在,我们将为Grub的配置文件生成一个模糊的密码。 只需键入grub-mkpasswd-pbkdf2并按Enter。 它会提示您输入密码,并给您一个长字符串。 用鼠标选择字符串,右键单击它,然后选择“复制”以将其复制到剪贴板中以备后用。

This step is technically optional — we can enter our password in plain text in Grub’s configuration files, but this command obfuscates it and provides additional security.

从技术上讲,此步骤是可选的-我们可以在Grub的配置文件中以纯文本形式输入密码,但是此命令会对其进行混淆并提供额外的安全性。

设定密码 (Setting a Password)

Type sudo nano /etc/grub.d/40_custom to open the 40_custom file in the Nano text editor. This is the place where you should put your own custom settings. They may be overwritten by newer versions of Grub if you add them elsewhere.

输入sudo nano /etc/grub.d/40_custom以在Nano文本编辑器中打开40_custom文件。 在这里应该放置自己的自定义设置。 如果将它们添加到其他位置,则它们可能会被较新版本的Grub覆盖。

Scroll down to the bottom of the file and add a password entry in the following format:

向下滚动到文件底部,然后添加以下格式的密码条目:

set superusers=”name” password_pbkdf2 name [long string from earlier]

设置超级用户=“名称” password_pbkdf2名称[较早的长字符串]

Here we’ve added a superuser named “bob” with our password from earlier. We’ve also added a user named jim with an insecure password in plain text.

在这里,我们使用先前的密码添加了一个名为“ bob”的超级用户。 我们还添加了一个名为jim的用户,该用户的纯文本密码不安全。

Note that Bob is a superuser while Jim isn’t. What’s the difference? Superusers can edit boot entries and access the Grub command line, while normal users can’t. You can assign specific boot entries to normal users to give them access.

请注意,鲍勃是超级用户,而吉姆不是。 有什么不同? 超级用户可以编辑启动项并访问Grub命令行,而普通用户则不能。 您可以将特定的引导条目分配给普通用户以授予他们访问权限。

Save the file by pressing Ctrl-O and Enter, then press Ctrl-X to exit. Your changes won’t take effect until you run the sudo update-grub command; see the Activating Your Changes section for more details.

通过按Ctrl-O和Enter来保存文件,然后按Ctrl-X退出。 您必须先运行sudo update-grub命令,所做的更改才会生效。 有关更多详细信息,请参见激活更改部分。

密码保护启动项 (Password Protecting Boot Entries)

Creating a superuser gets us most of the way. With a superuser configured, Grub automatically prevents people from editing boot entries or accessing the Grub command line without a password.

创建超级用户可以使我们受益匪浅。 配置了超级用户后,Grub会自动阻止人们编辑启动项或使用密码访问Grub命令行。

Want to password protect a specific boot entry so that no one can boot it without providing a password? We can do that too, although it’s a bit more complicated at the moment.

是否想用密码保护一个特定的启动项,以便没有提供密码就没人可以启动它? 我们也可以做到这一点,尽管目前情况有些复杂。

First, we’ll need to determine the file that contains the boot entry you want to modify. Type sudo nano /etc/grub.d/ and press Tab to view a list of the available files.

首先,我们需要确定包含要修改的启动项的文件。 键入sudo nano /etc/grub.d/ ,然后按Tab键查看可用文件列表。

Let’s say we want to password protect our Linux systems. Linux boot entries are generated by the 10_linux file, so we’ll use the sudo nano /etc/grub.d/10_linux command to open it. Be careful when editing this file! If you forget your password or enter an incorrect one, you won’t be able to boot into Linux unless you boot from a live CD and modify your Grub setup first.

假设我们要用密码保护我们Linux系统。 Linux引导条目由10_linux文件生成,因此我们将使用sudo nano /etc/grub.d/10_linux命令打开它。 编辑此文件时要小心! 如果您忘记了密码或输入了错误的密码,除非您从实时CD引导并首先修改Grub设置,否则您将无法引导至Linux。

This is a long file with a lot of stuff going on, so we’ll hit Ctrl-W to search for the line we want. Type menuentry at the search prompt and press Enter. You’ll see a line starting with printf.

这是一个很长的文件,其中包含许多内容,因此我们将按Ctrl-W搜索所需的行。 在搜索提示下键入menuentry ,然后按Enter。 您会看到一行以printf开头的行。

Just change the

只需更改

printf “menuentry ‘${title}’

printf“菜单'$ {title}'

bit at the start of the line to:

该行开头的位为:

printf “menuentry –users name ‘${title}”

printf“菜单–用户名'$ {title}”

Here we’ve given Jim access to our Linux boot entries. Bob also has access, since he’s a super user. If we specified “bob” instead of “jim,” Jim wouldn’t have any access at all.

在这里,我们已授予Jim访问我们Linux启动项。 由于Bob是超级用户,因此他也具有访问权限。 如果我们指定“ bob”而不是“ jim”,那么Jim根本没有任何访问权限。

Press Ctrl-O and Enter, then Ctrl-X to save and close the file after modifying it.

按Ctrl-O和Enter,然后按Ctrl-X保存并在修改后关闭文件。

This should get easier over time as Grub’s developers add more options to the grub-mkconfig command.

随着时间的流逝,随着Grub的开发人员向grub-mkconfig命令添加更多选项,这应该会变得更加容易。

激活您的更改 (Activating Your Changes)

Your changes won’t take effect until you run the sudo update-grub command. This command generates a new Grub configuration file.

您必须先运行sudo update-grub命令,更改才会生效。 此命令生成一个新的Grub配置文件。

If you password protected the default boot entry, you’ll see a login prompt when you start your computer.

如果您使用密码保护了默认启动项,则在启动计算机时会看到登录提示。

If Grub is set to display a boot menu, you won’t be able to edit a boot entry or use command-line mode without entering a superuser’s password.

如果将Grub设置为显示启动菜单,则在不输入超级用户密码的情况下,您将无法编辑启动项或使用命令行模式。

翻译自: https://www.howtogeek.com/102009/how-to-password-protect-ubuntus-boot-loader/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值