Learning Linux

GRUB password

Haz click aquí para leer en Español

Let’s work with Linux! With the knowledge and experience I have gained working in the IT industry, I have come to realize how critical it is to protect your servers. One easy thing to do is to set up GRUB password. How do I protect my Linux server and set up GRUB password? Let me show you how to set up GRUB in just a few steps, with some simple Linux commands.

Disclaimer: Running :(){:|:&}; : The above is actually a fork bomb. It operates by defining a function called ‘:‘, which calls itself twice, once in the foreground and once in the background. It keeps on executing again and again till the system freezes.

Why setting up GRUB password?

As you might know, if a hacker gains control of your system and somehow is able to reboot it, they can change root password Linux easily. It can be very easy to boot in single user mode and gain access/change root password

How to prevent access to grub editor?

On RHEL before 7

  1. Create a password for GRUB, be a root user and open command prompt, type the below command:


2. Paste the password into /boot/grub/grub.conf file 

ON RHEL 8 grub2

  1. Run vim /etc/grub.d/10_linux and go to the line CLASS

2. remove the –unrestricted

3. Run grub2-setpassword

4. The file user.cfg will be created under /boot/grub2/user.cfg  encrypted password

5. Recreate the grub config file grub2-mkconfig -o /boot/grub2/grub.cfg

6. Reboot command, to reboot the system

After rebooting, in order to edit/check the grub promp, you need to introduce the user and password if not, I won’t be able to access it.

Also, to remove the grub protection:

add once again –unrestricted to /etc/grub.d/10_linux and remove the user.cfg (Created on step 4)

Linux server is free and easy to install. Play around and you will have endless possibilities.

Udemy offers amazing IT related courses, go and check out their site!

Is Linux an operating system?

Yes, just like Microsoft Windows, macOS, iOS, Android, just to name a few.

Is it possible to reset GRUB password?

Yes, you can recover the GRUB password of the different Linux distros. If you log in to the server as root or as sudoers, you should be able to do it following above steps.

As you can see, it is an easy task!

Easy to play

For my following entries, I will write about SELinux, bootloader, initramfs, handy tools to work in Linux and more. Stay tuned and follow the blog!

If you have time, check my other posts and let me know if you have done something similar.


More resources:

If you want to know about Apache

If you want to know more about finances and investment in dividends

If you want to know about Ansible

More resources: grub rescue

One thought on “Learning Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: