Setting Password for Single User Mode in Linux adds security to Linux boxes. If someone accesses your server physically & reboots the server and then tries to change the root password from single-user mode. In that case, if the password is set on single-user mode, one has to first enter the root password, then only can reset the root password.
Note – In Debian-like Operating System requires a root password when booting into single user mode or recovery mode. But RHEL & CentOS allows access from the console into single-user mode without a password.
Setting password for Single user mode on CentOS/RHEL 5.x
Edit the file /etc/inittab, add ‘su:S:wait:/sbin/sulogin’ above the line initdefault as shown below:
# vi /etc/inittab # # inittab This file describes how the INIT process should set up # the system in a certain run-level. # # Author: Miquel van Smoorenburg,# Modified for RHS Linux by Marc Ewing and Donnie Barnes # # Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # su:S:wait:/sbin/sulogin id:5:initdefault:
Setting password for single user mode on CentOS/RHEL 6.x
Edit the file /etc/sysconfig/init & replace “SINGLE=/sbin/sushell” with “/sbin/sulogin” as shown below:
# What ttys should gettys be started on? ACTIVE_CONSOLES=/dev/tty[1-6] # Set to '/sbin/sulogin' to prompt for password on single-user mode # Set to '/sbin/sushell' otherwise SINGLE=/sbin/sulogin