Root Password
---
fsck -y -> Repair Linux Disk Using FSCK and Recover Linux Files
CentOS 7
1. First Line press e
2. press e to edit the existing kernel (Core) as shown below end.
change that ()ro to rw) ----rw init=/sysroot/bin/sh [ Change ro & add this line ]
3. press Control + X
4. # chroot /sysroot
5. # passwd root
6. # touch /.autorelabel
7. # exec /sbin/init
As the system boots, press ESC to bring up the GRUB boot prompt. The prompt happens early in the boot process. If you miss the prompt, you need to restart the server from the control panel and try again.
At the GRUB boot prompt, press E to edit the first boot option.
Find the kernel line starting with linux16.
Change ro to rw init=/sysroot/bin/sh.
Press CTRL+X or F10 to boot into single user mode.
Access the system with the command: chroot /sysroot.
Type passwd and follow the prompts to change the root password.
Run touch /.autorelabel to force file system relabeling. This is required for systems with SELinux. When you reboot the system, it will relabel the filesystem for SElinux. The reboot may take extra time during this process.
Run reboot -f to reboot the server.
CentOS 8
As the system boots, press ESC to bring up the GRUB boot prompt. The prompt happens early in the boot process. If you miss the prompt, you need to restart the server from the control panel and try again.
At the GRUB boot prompt, press E to edit the first boot option.
Find the kernel line starting with linux.
Change ro to rw init=/sysroot/bin/sh.
Press CTRL+X or F10 to boot into single user mode.
Access the system with the command: chroot /sysroot.
Type passwd and follow the prompts to change the root password.
Run touch /.autorelabel to force file system relabeling. This is required for systems with SELinux. When you reboot the system, it will relabel the filesystem for SElinux. The reboot may take extra time during this process.
Run exit.
Run logout.
Run reboot to reboot the server.
-----------------------------
CentOS 6
1. First Line press a [Type ‘a‘ to modify kernel argument.]
2. Add 1 at the end of rhgb quiet [ Add this line last=us rd_NO_DM rhgb quiet 1 ]
3. # runlevel
4. # passwd
5. # reboot
--------------------------------------
CentOS 5
1. First Line selected press e
2. module /vmlinuz-2.6.(Line 2) Press again e
3. ro linux single [ Add this line last=/ rhgb quiet ro linux single ]
4. press Enter
5. module /vmlinuz-2.6.(Line 2) Press b
6. # passwd root
--------------------------------------------
Forgotten Root Password On CentOS 7 Servers
At the boot menu, press e to edit the existing kernel (Core) as shown below.
Next, scroll down to the list until you see the line underlined below ( ro ) . What we need to do is change that ro to rw and start into a bash shell. It should look like this rw init=/sysroot/bin/sh
Change the ro line to rw and add init=/sysroot/bin/sh
rw init=/sysroot/bin/sh
After changing that, press Control + X or Ctrl + X on your keyboard to start into single user mode using the bash shell specified above. In this mode, we’re going to change the root password.
In the single user mode, run the command as shown below
# chroot /sysroot
Finally, run the commands below to change the root password.
# passwd root
You’ll be prompted to create and confirm a new password. After creating the password, run the commands below to update SELinux parameters
touch /.autorelabel
Reboot and login again to root account and see if everything works ok or not?
# exec /sbin/init
Clear in the above image that we have successfully log-in to RHEL 7 box by resetting root password from single user mode.
The above steps clearly showed how to login to RHEL 7 and CentOS 7 machine by resetting root password from single user mode.
XXXXXXXXXXXXXXXXXXXXXX________XXXXXXXXXXXXXXXXXXXX______________XXXXXXXXXXXXXXXXXXX
Boot in single user mode on CentOS 7 / RHEL 7
This guide will show you how to boot into single user mode on a CentOS 7 server. You'll need single user boot to recover a corrupt file system, reset the root password, ...
First, reboot your server and when you enter the Kernel Selection menu, press e to modify the parameters to boot the kernel.
The next screen will show you a confusing screen of kernel parameters. It'll look like this.
Scroll down until you find the actual kernel line. It starts with linux16 /vmlinuz-... and will span a couple of lines. You're now looking for the ro keyword in the kernel linux, which would start the OS with a read only (ro) file system.
Use your arrow keys to go to the ro line and replace it with rw init=/sysroot/bin/bash. The result should look like this. If that's the case, press ctrl+x to boot the kernel with those options.
If everything went fine, you're now in a limited shell with access to the entire filesystem. To make things easier, you can chroot the filesystem so you can access all your known files/directories with the same paths.
__________________CLI_____________________________
# push "e" key
CentOS Linux (3.10.0-327.4.4.el7.x86_64) 7 (Core) with debugging
CentOS Linux (3.10.0-327.4.4.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-327.3.1.el7.x86_64) 7 (Core) with debugging
CentOS Linux (3.10.0-327.3.1.el7.x86_64) 7 (Core)
CentOS Linux 7 (Core), with Linux 3.10.0-229.el7.x86_64
CentOS Linux 7 (Core), with Linux 0-rescue-ffa496be96ad482cb94373394cec7
Use the ^ and v keys to change the selection.
Press 'e' to edit the selected item, or 'c' for a command prompt.
setparams 'CentOS Linux (3.10.0-327.4.4.el7.x86_64) 7 (Core)' 'fedora'
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1' c4df086e-3699-4e02-b7cf-b47e614f6920
else
search --no-floppy --fs-uuid --set=root c4df086e-3699-4e02-b7cf-b47e614f6920
fi
# add "rw init=/bin/bash" to the end of line
# remove "rhgb", "quiet", "LANG=***" all if there are in this line
linux16 /vmlinuz-3.10.0-327.4.4.el7.x86_64 root=/dev/mapper/centos-root \
ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap console=ttyS0,115200n8
systemd.debug rw init=/bin/bash
initrd16 /initramfs-3.10.0-327.4.4.el7.x86_64.img
Press Ctrl-x to start, Ctrl-c for a command prompt or Escape to
discard edits and return to the menu. Pressing Tab lists
possible completions.
# after inputting above, push "Ctrl-x" key to proceed
.....
.....
[ OK ] Stopped udev Coldplug all Devices.
Stopping udev Coldplug all Devices...
[ OK ] Started Plymouth switch root service.
[ 6.814528] systemd-journald[95]: Received SIGTERM from PID 1 (systemd).
bash-4.2#
# after initramfs switch_root prompt is displayed, do like follows
# set SELinux relabeling on next boot if you enabling SELinux
bash-4.2# touch /.autorelabel
# set password
bash-4.2# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
# restart System and complete to reset
bash-4.2# exec /sbin/init
XXXXXXXXXXXXXXXX_-------------XXXXXXXXXXXXXXXX---------------XXXXXXXXXXXXXXXx
Root Password On CentOS 6
STEP 1. Boot Computer and Interrupt while booting at GRUB stage hitting ‘arrow‘ keys or “space bar“.
Booting GRUB Stage
STEP 2. Type ‘a‘ to modify kernel argument. Anytime you can cancel typing ‘ESC‘ key.
Modify Kernel Argument
STEP 3. Append 1 at the end of “rhgb quiet” and press “Enter” key to boot into single user mode.
Append 1 at the Screen
STEP 4. Type command “runlevel” to know the the runlevel where you are standing. Here “1 S” state that your are in a single user mode.
Type Command runlevel
STEP 5. Type ‘passwd‘ command without username and press ‘Enter‘ key in command prompt. It’ll ask to supply new root password and re-type the same password for confirmation. “Your are Done” Congratulation!!!
Type passwd Command
xx
XXXXXXXXXXX-----------------XXXXXXXXXXXXXXXXXX-----------XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Boot in single user mode on CentOS 5
Take look on the following picture you will find that grub counting the time to boot the default operating system as mentioned in /etc/grub.conf.
That time press any key to interrupt, you will see the list of kernel that is installed on the machine. In my case there are three kernels.
Updated centos kernel with xen.
Default installed kernel with xen.
Default installed kernel without xen.
Select the kernel in which you want to login by using arrow keys, once selected press ‘e’ to edit the kernel parameters. Once press you will find the screen like below.
Now you go to the third line, which starts with module /vmlinuz-2.6.xx.xxx.x.xen ro root=LABEL=/ rhgb quiet. Press again “e“ to edit.
At the end of the line insert word “ro linux single”. It will look like below.
If you see full line, it looks module /vmlinuz-2.6.xx.xxx.x.xen ro root=LABEL=/ rhgb quiet ro linux single
Once done press Enter, you will get the following screen with selection of third line. Press ‘b’ to boot the kernel with edited parameter.
Once booted it will go to hash prompt i.e. root prompt without asking password. See below.
# passwd root
That’s it.
------