Single User Mode in CentOS 7 / RHEL 7

ADVERTISEMENT

CentOS 7

Single user mode is the one of the Run level in the Linux operating system, Linux operating system has 6 run levels that are used for different requirement or situation. Single user mode mainly used for doing administrative task such as cleaning the file system, Managing the quotas, Recovering the file system and also recover the lost root password. In this mode services won’t start, none of the users are allowed to login except root and also system won’t ask for password to login.

ADVERTISEMENT
Article will continue after the ad

Step 1: While booting you might see the splash screen like below, grub is counting the time to boot the default operating system as mentioned in /etc/grub2.cfg; this time press any key to interrupt the auto boot.

CentOS 7 - Reset root Password Autoboot
CentOS 7 – Reset root Password Auto boot

Step 2: It will list operating systems (in my case only CentOS installed) that you have installed on the machine, In below that you might find some information about booting the OS and editing the parameters of menu. If you want to enter into single user mode; select the operating system and press “e” edit arguments of kernel.

CentOS 7 - Reset root password - Select Kernel
CentOS 7 – Reset root password – Select Kernel

Step 3: Once you have pressed, you should see the information about the selected operating system. It gives you the information about the hard disk and partition where the OS installed, location of the kernel, language, video output, keyboard type, keyboard table, crash kernel and initrd (Initial ram disk).

To enter into single user mode; Go to second last line (Starts with linux 16 or linuxefi) using up and down arrow then  modify the ro argument.

CentOS 7  - Reset root password - Before changing Kernel Argument RO
CentOS 7 – Reset root password – Before changing Kernel Argument

Step 5: Modify it to “rw init=/sysroot/bin/sh”. Once done, press “Ctrl+x”

CentOS 7  - Reset root password - After changing Kernel Argument
CentOS 7 – Reset root password – After changing Kernel Argument

Now you should be in command line mode with root privileges (without entering password). Now you can start to troubleshoot your system or can do maintenance of your system.

CentOS 7 - Single user mode
CentOS 7 – Single user mode

chroot to access your system.

chroot /sysroot

That’s all, You must chroot to reset root password in CentOS 7 / RHEL 7

ADVERTISEMENT

POSTS YOU MAY LIKE -:)

Share This Post

  • Nicholas

    hello,I have changed my password in your guide.But I can’t login with my new password,I have tried many times,and failed

  • Robert

    This worked well for me in conjunction with your password reset guide for CentOS 7. I also checked the CentOS wiki and its Red Hat documentation for this process has the same basic steps that you gave, but your tutorial is much more refined and user-friendly. Thank you.

  • H4nd0

    This is an extremely dangerous procedure when SELinux is enforcing. If you choose to boot into /bin/sh using this method, chroot and then passwd your machine will not boot multiuser when you reboot as /etc/passwd will no longer be readable by sshd and other daemons during boot as the SELinux context and label has changed. Ensure you check the SELinux label on /etc/passwd before resetting the root passwd (ls -Z /etc/passwd and ls -Z /etc/shadow) and ensure you set the labels back accordingly using restorecon before rebooting.

    • David Betz

      After resetting pw, just do “touch /.autorelabel”.

  • Peppol

    If I try this method to boot into Single User Mode the boot process ‘hangs’ after the message:
    [ OK ] Reached target Initrd Default target.
    Is it common to wait very long after this or is ther an other way to boot into Single User Mode without root password?

  • Simon Peeters

    THIS ARTICLE IS SOO WRONG.

    first to get into single user mode you just need to add ‘single’ to the kernel commandline. the system will boot and ask your root pasword and give you a shell.

    WHAT THESE STEPS DO:
    First of you give a parameter to systemd in the initrd that you want to use /sysroot/bin/sh as init system.
    When systemd has mounted your root partition it tries to execute /sysroot/bin/sh on your root filesystem. WHICH DOES NOT EXIST.
    This failure causes systemd to revert to launching an emergency shell inside the initrd.
    Then since you are still inside the initrd, you can indeed chroot into your real system (mounted at /sysroot by the initrd)

    Shorter way to a root shell without a password:
    just add “init=/bin/sh” to your commandline

    • aefwon

      correct , that has been since ages, just mention single or 1 at end of the kernel parameters

      • David Betz

        That was changed in RedHat 7 (therefore, Centos 7). “single” now requires a password; you now boot to a shell to reset root pw.

Shares