Linux run level and root password retrieval

Linux run level

Basic introduction The
Linux system has 7 operating levels, ranging from 0-6, with different functions. These levels are specified in the /etc/inittab file. This file is the main file that the init program looks for. The first service to run is the file placed in the /etc/rc.d directory. In most Linux distributions, the startup script is located in /etc/rc.d/init.d. These scripts are connected to the /etc/rc.d/rcn.d directory with the ln command. (The n here is run level 0-6).

Run level description

  • 0: Shutdown The
    default operating level of the system cannot be set to 0, otherwise it will not start normally, and it will automatically shut down as soon as it is turned on.
  • 1: Single user (retrieve lost password)
    root authority, used for system maintenance, remote login is prohibited, just like the safe mode login under Windows.
  • 2: There is no network service in the multi-user state
  • 3: Multi-user status has network status
  • 4: The system is not used, reserved for users
  • 5: Graphical interface
  • 6: Restart the system The
    default run level cannot be set to 6, otherwise it will not start normally, it will always be restarted and restarted.

Insert picture description here

View current run level

vim /etc/inittab

# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used 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)
# 
id:5:initdefault:

The current run level is 5

Switch run level

init 数字(0-6)

Detailed steps to retrieve root password

Specific steps

  1. Turn on.
  2. Enter the Enter key when booting.
  3. See an interface and enter e.
  4. See a new interface, select the second line (Edit Kernel) and enter e.
  5. Enter 1 at the end of this line, and then enter the Enter key.
  6. Enter b again, then you will enter the single user mode.
  7. Finally enter the single-user mode and use the passwd command to modify the root password.

Demo process

After entering the Enter key during booting, you can see the following interface.
Insert picture description here
After entering e, you can see the following interface.
Insert picture description here

Then enter e to see the interface below, highlight the cursor to the second line, the line circled in red.
Insert picture description here
After entering e, you can see the following interface.
Insert picture description here
Enter space 1 and press Enter.
Insert picture description here
Enter e again, and it will enter single user mode.
Insert picture description here
Use the passwd command to change the password.
Insert picture description here
The password is changed successfully, and finally restart.
Insert picture description here
Note: There is a prerequisite to retrieve the root password through the above method, that is, it must be operated on the computer where the linux system is located, and cannot be retrieved by remote login.

Guess you like

Origin blog.csdn.net/weixin_44736475/article/details/108967046