Without a doubt, one of the most powerful and essential tools a system’s administrator has is the ability to gain root privileges. While it’s generally a bad idea, to say the least, to perpetually operate as the root user on any given system, being able to log in as the root user on the command console is essential at times. Therefore, it’s frustrating to be in the position as a system administrator if you’ve forgotten or otherwise lost the password and are, subsequently, unable to gain escalated privileges on a system.
Since the shift to grub2, as well as other changes with the init system, the method of gaining access to a system for such low-level purposes has changed .
Reboot the system, wait for the grub menu, press the letter ‘E’ on the keyboard to edit the menuentry. Then, scroll down to the bottom of the screen to the line starting with linux
and append the space-separated kernel commands rw
and init=/bin/bash
before hitting the F10 key to boot the edited menu entry.
This will boot the system into a bash
shell with the root partition mounted in
rw
mode (read-write permissions).
NOTE: The previously-advised method of booting into single
user mode, or
runlevel 1 should not be advised, as the rescue-shell now expects the user to enter
the root
password before allowing access to it.
Booting the system using bash
will allow the user to finally change the password
with the appropriate
# passwd
command.
Furthermore, however, in order to make sure that SELinux file contexts are
restored properly after the password modification, execute:
# touch /.autorelabel
before restarting the virtual system.
To restart the virtual machine, execute
# /sbin/reboot -f