How to recover your lost root password in CentOS

Here is a handy report on how to reset your root password if you have console access.

How to recover your lost root password

In CentOS, it’s possible to have the scripts that run from the initramfs debug the shell at certain points, provide a root shell, and continue when that shell exists.

First, reboot the system.

linux root password

Interrupt the boot loader countdown by pressing any key.

Move the cursor to the entry that needs to be booted.

linux root password

Press “e” to select that entry. After selecting that entry, the below kernel commands will appear.

linux root password

In the kernel command line, move the cursor to the line that starts with linux16.

linux root password

Press the “End” key to move the cursor to the end of it. Type “rd.break” (This will break just before control is handed from the initramfs to the actual system).

linux root password

Then press “Ctrl+x” to save those changes. The Initramfs debug shell will appear.

linux root password

Next, we have to provide read and write permissions to /sysroot by typing the below command:

mount -o remount,rw /sysroot/
linux root password

Now switch into chroot jail.

chroot /sysroot
linux root password

In here, /sysroot is treated as the root of the file system tree.

Next you’ll set a new root password.

passwd root
linux root password

And relabel the files.

touch /.autorelabel
linux root password

Finally, type “exit” twice.

The first one will exit from the chroot jail.

linux root password

The next one will exit from the initramfs debug shell and reboots the system.

linux root password

How to amend the emails from Cpanel backups to the current account

If a customer happens to delete their emails you can still retrieve them from the cpanel backup system. This will take root access to move the files from the backup folder tot he customers account.

You can extract a backup archive and copy over the emails to an account’s existing mail directory. If restoring a backup archive, you will find emails located at:

Code:
/home/cpmove-username/homedir/mail/domain.com/email-account/

You can also find emails from the default account within:

Code:
/home/cpmove-username/homedir/mail/

The following thread is intended for manual migrations to cPanel, but it includes details about the maildir structure that will be useful to you:

Manual Migrations to cPanel