The root password of the Linux operating system is forgotten.

Reinstall the system? Of course not! The simplest method: enter single user mode and change the root password.

The steps are as follows:

Restarting the Linux OS

Press Enter within 3 seconds to display the following interface

And then type e

Type single at the end of the second line with a space. Press the down arrow to move to the second line and press “E” to enter editing mode

Enter single after it

Finally, press “B” to start up, and then enter single-user mode

Now that you have entered single-user mode, you can change the root password. The password change command is passwd

[Rescue mode using system installation CD]

The rescue mode is rescue, which is mainly applied to the situation that the system cannot enter. For example, GRUB is corrupted or a configuration file has been modified incorrectly. How to use rescue mode?

CD boot, press F5 to enter rescue mode

Type Linux rescue and press Enter

Choose a language. I suggest you choose English

Select us keyboard

Here you are asked if you have the network enabled, sometimes it may be online debugging. We chose the no

This tells us that the system will then be mounted in/MNT /sysimage.

There are three options:

  • Continue is the next step after the mount.
  • Read-Only Mount the file in read-only mode, which is safer. In some cases, read-only mode prevents the file system from further corruption.
  • To Skip means to not mount and go to a command window mode.

Here we choose Continue.

At this point, the system is mounted in/MNT /sysimage. Enter chroot/MNT /sysimage to enter the administrator environment.

You can also change the password of root to rescue mode. This Rescue mode is very similar to Windows PE system.

When chroot/MNT /sysimage/ is run, ls can see that the directory structure is the same as the original system directory structure.

That’s right! The current environment is exactly the same as the environment of the original system. You can either type Exit or press Ctrl + D to exit the environment. Then you can check it again

This directory is actually a directory structure in rescue mode, and all our system files are in/MNT /sysimage directory.

Some friends will also directly through the modification of the password to solve, modify the password in the process of what problems will appear? How to solve it?

When you run the passwd root command to change the password of user root in Linux, the following information occurs:

# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: Authentication token manipulation error
Copy the code

The inodes partition is not in the root partition, but the inodes partition is not in the root partition.

# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 6406144 58534 6347610 1% /
tmpfs 8242797 2 8242795 1% /dev/shm
Copy the code

/etc/passwd and /etc/shadow files /etc/passwd and /etc/shadow files /etc/passwd

# lsattr /etc/passwd -- I -- e- /etc/passwd # lsattr /etc/shadow -- I -- e- /etc/shadowCopy the code

Note: On Linux, the “I” option means that no changes can be made to the file, which causes password changes to fail.

To resolve the problem, run the chattr -i command to revoke the permissions of the two files I

# chattr -i /etc/passwd
# chattr -i /etc/shadow
# lsattr /etc/passwd
————-e- /etc/passwd
# lsattr /etc/shadow
————-e- /etc/shadow
Copy the code

Then run passwd to change the password.

# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Copy the code

After the password is changed, run the chattr + I command to grant I permission to the password system file for security purposes

# chattr + I /etc/passwd # chattr + I /etc/shadow # lsattr /etc/passwd -- I -- e- /etc/shadowCopy the code