Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Access to Single User Mode in Rocky Linux / AlmaLinux

Leer en espanol
Access to Single User Mode in Rocky Linux / AlmaLinux

Table of contents

Single User Mode (also known as Maintenance Mode or Rescue Mode) is an essential tool for system administration and recovery in Linux. This mode will ===

1. Introduction

He Single User Mode  (also known as Maintenance Mode or Rescue Mode) is an essential tool for system administration and recovery in Linux. This mode allows you to access the system as the root user without the need for a password, which is essential to perform critical tasks such as:

  • Reset user passwords.

  • Repair corrupted file systems.

  • Troubleshoot boot or operating system configuration issues.

2. Procedure to Access Rescue Mode

To boot the system in rescue mode, you must temporarily modify the GRUB boot configuration.

2.1. Access the GRUB menu

  1. Reboot your system.

  2. Right when the machine is booting, press a key to access the GRUB menu. Generally it is the key Esc either Shift.

  3. Use the arrow keys on your keyboard to select the kernel entry you want to boot (usually the first option).

Acceso a Single User Mode en Rocky Linux / AlmaLinux

2.2. Edit kernel boot entry

  1. With the kernel entry selected, press the key e to edit it.
  2. Find the line that starts with linux either linux16 (depending on GRUB version). This is the line that loads the kernel.
  3. Go to the end of that line and add one of the following options:
CODE
rd.break enforcing=0

Alternatively:

CODE
single
  • rd.break: This is the option recommended for systems that use systemd (like Rocky and AlmaLinux). It stops you just before control is passed to systemd, leaving you in a rescue shell.

  • single: An alternative option, less common in modern systems, but in some cases it can work.

3. Start the System in Rescue Mode

  1. Once you have added the chosen option, press Ctrl + X either F10 to boot the system with the modified configuration.

  2. The system will boot into an emergency shell environment, where you will see a prompt of sh

Acceso a Single User Mode en Rocky Linux / AlmaLinux

4. Prepare the File System

In this environment, the main file system (/sysroot) is usually mounted in read-only mode to prevent corruption. You must remount it in read/write mode to make changes.

Run the following command to remount the file system:

CODE
mount -o remount,rw /sysrootchroot /sysroot

Now, change the root environment (chroot) to make the shell work with your operating system files:

CODE
chroot /sysroot
Acceso a Single User Mode en Rocky Linux / AlmaLinux

You can now execute administration commands, such as changing the user's password root:

CODE
passwd root

5. Security Considerations (SELinux)

If your system uses SELinux (which is most common), it is crucial to relabel files to ensure that new changes, such as the password, work correctly after the reboot.

Create a file called .autorelabel at the root of the system. This tells SELinux to retag everything on the next boot.

CODE
touch /.autorelabel
Después de reiniciar, SELinux detectará este archivo y comenzará el proceso de reetiquetado, lo que puede tardar varios minutos.

6. End Session and Restart

Once you have completed your tasks, exit the environment chroot with the command exit:

CODE
exit

Finally, reboot the system so that all changes are applied correctly:

CODE
reboot

:wq!

Comments