If you have some old CentOS 7 Virtual machine hanging for a long time and you don't remember the root password or you don't remember where you have stored it, but you have something important as data left over, you might need to recover root password for your CentOS 7 Virtual Machine.
I recently had to resolve that issue and here is the few easy steps to take to recover the lost root password.
Assuming you have tried to boot the VM and the VM boots fine and your few attempts to input manually some default passwords of yours failed, next
1. Reboot the Virtual Machine to the GRUB boot menu
The GRUB boot screen should appear and be there for few secs
2. Edit the boot loader kernel options ( add add rd.break enforcing=0 )
Press 'e' to Edit the boot loader and modify the boot commands options passed to the linux kernel.
In GRUB edit mode:
add rd.break enforcing=0
to the end of the line starting with linux at the end of passed parameters list as shown in the picture.
When done editing, press Ctrl-x (Control button x key simultaneously) to boot with changed parameters.
ALTERNATIVE WAY TO BOOT THE SYSTEM INTO ROOT WITHOUT PASSWORD PROMPT:
Alternative options to use instead of add rd.break.enforcing=0 are to substitute the rhgb quiet kernel option with init=/bin/bash
As you might wonder for the meaning of the passed 2 parameters:
rd.break breaks the boot process at initramfs while
enforcing=0 disables the SELinux (which often enabled by default on CentOS).
Another way is to
3. Boot in CentOS emergency mode and Reset the root password
When done editing, press Ctrl-x to boot with changed parameters.
As you might wonder for the meaning of the passed parameters:
rd.break breaks the boot process at initramfs while
enforcing=0 disables the SELinux (which often enabled by default on CentOS).
Whence system boots up with the modified kernel options cmd, the switch_root prompt will appear.
As the emerency mode boots the filesystem into read-only mode under /sysroot default directory, in order to be able to
modify the MD5 root password stored hash inside RO mounted /sysroot/etc/shadow you need to remount the Filesystme
in read-write mode.
To Remount the read-only file system /sysroot in write mode:
# mount -o remount,rw /sysroot
As the /sysroot is not the root directory to be able to use a standard passwd command you need to make /sysroot
as the default root folder for the booted linux by chrooting into it.
- Generate MD5 password manually (for Hardcore masochistic admins 🙂 )
If you're a hard core linux sysadmin of course, generate your own new md5 password and directly modify /etc/shadow copy pasting the md5 string.
If you want to manually generate the md5 string, you can do it depending on the required encryption algorithm with:
For (md5, sha256, sha512) encrypted pass
# openssl passwd -6 -salt xyz yourpass
For (md5, sha256, sha512) encrypted pwd
# mkpasswd –method=SHA-512 –stdin
For (des, md5, sha256, sha512) encrypted pw
# perl -e 'print crypt("YourPasswd", "salt", "sha512"),"\n"'
Once the string is generated;
# vim /etc/shadow
and exchange the old with new string for MD5
- Change password with chroot (the easy common way)
# chroot /sysroot
That should drop you into another shell bash-4.x
# passwd
Changing password for user root.
New password:
Retype new password:
We need have to sync the entire filesystem we have to use the sync command, for novice sys admins who never heard about this command, below
short description:
The Linux sync command synchronizes cached data to permanent storage.
This data includes modified superblocks, modified inodes, delayed reads and writes, and others. sync uses several system calls:
sync()
syncfs()
fsync()
fdatasync()
For example, the sync command utilizes the sync() system call to write all buffered modifications to file data and metadata to an underlying storage device.
As a Linux systems administrator or developer, understanding the sync command can be crucial for efficient file synchronization. Additionally, sync can be helpful after crashes or when the file system becomes corrupted.
In this tutorial, we’ll explore the various aspects of the sync command. Also, we’ll see how we can use sync in different scenarios.
# sync
# exec /sbin/init
Try out the root password after booting normally into CentOS and the new set administrator pass should work.
Resetting forgotten (lost) root password on CentOS 6
The process is absolutely the same except on the Step 1 (in the modification of GRUB boot menu by pressing e key), add to
rhgb quiet
at the end one 'S'
This S character means 'boot CentOS into Single user mode'
rhgb quiet S
Then, press ENTER key and press b key to boot CentOS 6 into to single user mode.
How to enable Ctrl+Alt+Backspace in Ubuntu 11.10 (Oneiric Ocelot) Linux
Monday, January 16th, 2012My sister, experience some programs running with wine (Windows Emulator) to crash on her Ubuntu 11.10.
As she is quite new with Linux, she has no idea about the existence of CTRL ALT BACKSPACE key combination to restart a hanged GNOME, KDE by directly killing the Xorg server.
I felt obliged to explain her it is better to use CTRL ALT BACKSPACE X kill switch instead of restarting the whole Linux kernel (which basiclly is working) and that it is just the display keeping blacnk.
Pressing the would kill Xorg and therefore all applicatins previously running on top of it will die. In Ubuntu Xorg is configured to run via gdm, so once killed it will automatically reload the GDM (Gnome Display Manager).
I was about to explain her that its better she use CTRL+ALT+BACKSPACE instead of restarting the whole system but suddenly I realized this is not working.
In UBUNTU 11.10 and I guess in all UBUNTU's after 9.04 CTRL ALT BACKSPACE is substituted with the key switch combination ALT PRINTSCREEN K, I've explained her about that.
This change is actually a change implied by most Linux distributions nowdas and is some kind of change in Xorg newer versions…
To enable back the CTRL + ALT + BACKSPACE , I've issued cmd:
stanimira@ubuntu~:$ echo' setxkbmap -option terminate:ctrl_alt_bksp' >> ~/.xinitrc
An alternative way to set setxkbmap -option terminate:ctrl_alt_bksp to run on Ubuntu user login is by setting it as a startup application using;
stanimira@ubuntu:~$ gnome-session-properties
Press the Add button and type in the box to appear;
Name: setxkbmap
Command: setxkbmap -option terminate:ctrl_alt_bksp
Comment: setxkbmap
Reverting the Xserver kill switch back to the classical Ctrl+Alt+Backspace should also be running fine on older Ubuntu Linuces – 11.04, 10.10, 10.04 etc.
Tags: add button, Alt, Auto, backspace, Button, change, Comment, Ctrl, Display, Draft, existence, GDM, Gnome, kde, key switch, kill, kill switch, Linux, linux kernel, login, most linux distributions, ocelot, option, Press, printscreen, Reverting, session properties, setxkbmapCommand, startup, startup application, switch combination, type, Ubuntu, wine, wine windows, xinitrcAn, Xorg, xserver
Posted in Linux, Linux and FreeBSD Desktop | No Comments »