How to: Reset forgotten CentOS 8 root password easily & quickly (CentOs 8 on UEFI) (& Red Hat Enterprise Linux/RHEL)

CentOS 8

1 Start the system

2 At the grub menu screen, press Up/Down Arrow keys on the keyboard to stop count down timer

CentOS 8 grub menu
CentOS 8 grub menu

3 Highlight the default boot item, usually the first one, press “e” key on the keyboard, to edit the boot option

The default content is as shown

Default CentOS 8 UEFI grub menu
Default CentOS 8 UEFI grub menu
load_video
set gfx_payload=keep
insmod gzio
linux ($root)/vmlinuz-4.18.0-147.5.1.el8_1.x86_64 root=/dev/mapper/cl-root ro \
crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swa\
p rhgb quiet
initrd ($root)/initramfs-4.18.0-147.5.1.el8_1.x86_64.img $tuned_initrd

We add “rd.break” at the end of “quiet” before “initrd”

Before

Before editing
Before editing

After

After editing
After editing
load_video
set gfx_payload=keep
insmod gzio
linux ($root)/vmlinuz-4.18.0-147.5.1.el8_1.x86_64 root=/dev/mapper/cl-root ro \
crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swa\
p rhgb quiet rd.break
initrd ($root)/initramfs-4.18.0-147.5.1.el8_1.x86_64.img $tuned_initrd

4 Use Ctrl + X key combination to start/boot the system

Booted
Booted

5 Input following commands

mount -o remount,rw /sysroot
chroot /sysroot
passwd

We will be asked for setting new root password, to be safe, we should input a password that is strong enough, at least 8 characters, can’t be among the common password list.

Otherwise it will complain “BAD PASSWORD: The password is shorter than 8 characters” or “BAD PASSWORD: The password fails the dictionary check – it is too simplistic/systematic”, we can ignore it and continue with the weak password if it’s just for testing purpose.

BAD PASSWORD: The password is shorter than 8 characters
BAD PASSWORD: The password is shorter than 8 characters
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
BAD PASSWORD: The password fails the dictionary check – it is too simplistic/systematic

Continue with following command

touch /.autorelabel
exit
reboot

FYI (Complete commands)

mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit
reboot

6 We now have successfully rest forgotten password for CentOS 8 on UEFI, now we can login with the new password.

Red Hat Enterprise Linux 7 and 8/RHEL 7 and 8

The procedure is very similar with CentOS 8.

The only difference is, instead of adding the “rd.break” at the end of “quiet” we need to find “quiet LANG=en_US.\ UTF-8″ then at the end add ” rd.break”, again, the process is very similar.

The rest will be exactly the same


How to reset Kali Linux forgotten root password – Reset Kali Linux password with single-user mode

(Single-user mode will not ask for username and password for login, the user has superuser rights)

1 Boot into GRUB menu

1.1 Power on the Kali Linux

1.2 When following boot screen appears, press key to stop the “Booting in x seconds” counter.

Kali Linux 2019.4, 2020 - Boot screen
Kali Linux 2019.4, 2020 – Boot screen

2 Edit GRUB menu

2.1 Make sure the first option “Kali GNU/Linux” is highlighted.

2.2 Press “e” key to enter GRUB menu edit mode

Kali Linux 2019.4, 2020 - GRUB menu edit mode
Kali Linux 2019.4, 2020 – GRUB menu edit mode

2.3 Find line start with “linux”

Find line start with "linux"
Find line start with “linux”

2.4 Use arrow keys to navigate, change “ro” to “rw”, append “init=/bin/bash” at the end of the line

Use arrow keys to navigate, change "ro" to "rw", append "init=/bin/bash" at the end of the line
Use arrow keys to navigate, change “ro” to “rw”, append “init=/bin/bash” at the end of the line
Modified line
Modified line

2.5 Use Ctrlx or F10 to boot with modified line, follow screen will appear

Single-user mode
Single-user mode

3 Change password

3.1 Enter following command

# passwd

3.2 Enter new password then retype the new password

Change password
Change password

Now restart the system with physical button (Do not use reboot command this time)

Now you can login with the new password.

Bonus:

With most Linux distributions we can use following routine to reset the forgotten password

1 Enter GRUB menu with editing mode

2 Add single-user boot option to GRUB menu

3 Boot with modified GRUB menu

4 Change password with “passwd” command

5 Reboot with physical button

Turn off display automatically on Ubuntu 18.04 server with text boot

Open /etc/default/grub in any text editor (e.g. sudo nano, sudo vi etc.)

Add consoleblank=0 to GRUB_CMDLINE_LINUX_DEFAULT= as parameter.

e.g.

If it is GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" change to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash consoleblank=0"

If it is GRUB_CMDLINE_LINUX_DEFAULT="text" change to GRUB_CMDLINE_LINUX_DEFAULT="text consoleblank=0"

Finally, do sudo update-grub then reboot.

Note: If you already boot from text mode, chance is you will have GRUB_CMDLINE_LINUX_DEFAULT=”text”

What does this change do?

Without consoleblank=0 after the server boot into text mode, after timeout, the screen will go blank with screen powered on (Dimmed screen), adding consoleblank=0 at the end of GRUB_CMDLINE_LINUX_DEFAULT=, will actually turn off the display after timeout instead of dim the display.

Alternatively, if you are running server on a laptop, the easiest way is to close the lid and still keep the server running, refer to this post: How to: Keep Ubuntu Server running on laptop with lid closed