RHEL: Force system to prompt for password in Single User mode

RHEL: Force system to prompt for password in Single User mode

# Tested on RHEL 5, 6 & 7

# Due to security reasons, one may want to force system to prompt for root password even
# in Single User mode

# By default, system doesn't ask for password and we are given root shell directly. Indeed,
# usually Single User mode is used to reset root password in case we forgot it.

# Note that after modifying configuration, in case of forgotten root password, you'll have
# to boot the system in rescue mode to revert configuration in order to be able to change
# root password in Single User mode.



# RHEL 5
# ------------------------------------------------------------------------------------------

# To force users to enter password in Single User mode, add following line to /etc/inittab:

~:S:respawn:/sbin/sulogin

# The changes to this file takes effect after a system reboot

# To make init re-read the /etc/inittab without rebooting the system, type the command

/sbin/init q



# RHEL 6
# ------------------------------------------------------------------------------------------

# Edit /etc/inittab and add "su:S:wait:/sbin/sulogin" before 'initdefault' line:

vi /etc/inittab
   [...]
   su:S:wait:/sbin/sulogin
   id:3:initdefault:

# Edit /etc/sysconfig/init and replace "SINGLE=/sbin/sushell"  with "SINGLE=/sbin/sulogin":

vi /etc/sysconfig/init
   [...]
   # Set to '/sbin/sulogin' to prompt for password on single-user mode
   # Set to '/sbin/sushell' otherwise
   SINGLE=/sbin/sulogin



# RHEL 7
# ------------------------------------------------------------------------------------------

# By default, Single User mode is password protected by the root password on RHEL 7:

cat /usr/lib/systemd/system/rescue.service
   [...]

   [Service]
   Environment=HOME=/root
   WorkingDirectory=/root
   ExecStartPre=-/bin/plymouth quit
   ExecStartPre=-/bin/echo -e 'Welcome to emergency mode! After logging in, type [...]
   ExecStart=-/bin/sh -c "/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default" <---
   Type=idle
   StandardInput=tty-force
   StandardOutput=inherit
   StandardError=inherit
   KillMode=process
   IgnoreSIGPIPE=no
   SendSIGHUP=yes
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
linux ssh How to Hide the OpenSSH Version Details when Telnet to Port 22
Viewed 5523 times since Wed, Apr 22, 2020
RHCS6: Quorum disk and heuristics
Viewed 4519 times since Sun, Jun 3, 2018
LUKS List available methods of encryption for LUKS
Viewed 3088 times since Fri, Jul 13, 2018
LVM: Mount LVM Partition(s) in Rescue Mode
Viewed 5022 times since Sat, Jun 2, 2018
stunnel: Authentication
Viewed 9270 times since Fri, Sep 28, 2018
10 nmap Commands Every Sysadmin Should Know
Viewed 10103 times since Wed, May 22, 2019
Df command in Linux not updating actual diskspace, wrong data
Viewed 3033 times since Wed, May 30, 2018
Linux - Cannot login from remote console but can access via ssh
Viewed 5387 times since Fri, Jun 8, 2018
Install OpenVPN On CentOS / RHEL 7
Viewed 3164 times since Fri, May 15, 2020
Monitoring bezpieczeństwa Linux: integracja auditd + OSSEC cz. I
Viewed 2593 times since Fri, Apr 5, 2019