You've forgotten the root password of a VM with console access only. How do you regain access?
IntermediateScenarioPackages, kernel and boot
Answer
Situation read → Interrupt boot and get a shell before login.
What I'd do →
- At GRUB press
e, appendrd.break(RHEL) orinit=/bin/bash(others) to thelinuxline, boot withCtrl+x. - RHEL with
rd.break:
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
touch /.autorelabel # SELinux relabel
exit; exit
- With
init=/bin/bash:mount -o remount,rw /,passwd, thenexec /sbin/init.
Why → The .autorelabel step fixes the SELinux label on /etc/shadow, or nobody can log in.
Interview tip → Mention that this is why physical/console access equals root, and GRUB passwords exist.
More on Packages, kernel and boot
You must upgrade the kernel on 50 production servers and be able to roll back if the new kernel misbehaves. Plan it.AdvancedYou need to pin a package version so routine updates don't upgrade it (e.g. Docker or PostgreSQL). How?BeginnerA package update broke an application. How do you roll it back?IntermediateYour servers can't reach the internet but need packages. How do you provide repositories?IntermediateYou need to compile and install software from source on a server that also uses packages. How do you avoid making a mess?IntermediateYou need to change kernel boot parameters (e.g. add `transparent_hugepage=never`) persistently. How?Intermediate