Restore the root password under slackware

Source: Internet
Author: User
Article Title: Restore the root password under slackware. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Everyone may lose something. What if I lose the root password of my server?

It doesn't matter. We use the following method to restore.

Recovery Method

Method 1:
Use lilo to set init = "/bin/bash to start and change the password. Method 2: Use a CD to start, Mount/partition, and modify the/etc/shadow file to clear the password.

Method 1: Start linux first. When lilo appears, we can stop lilo with one click (do not press Enter)

At this time, a picture similar to the following will appear.

Here we can see that there is only one system in the lilo list, that is, the system with the startup Item named slack.

Run the following command to start the system:

Slack init =/bin/bash rw

Note: The slack in the above command corresponds to the startup Item Name. The name of the system you set in your lilo is replaced by the name you set.

After the system enters the system, the following prompt appears:

Bash-3.00 # input at the end of the prompt

Passwd follow the instructions given to us and enter a new password two to three times.

Because the current system is only a very small kernel system, we should not perform any other operations, nor exit shell with exit. After modifying the password, we will use the following command to make the/directory read-only

Mount-o remount, rw/

Now you can safely restart the system.

Method 2 implementation process

 
We use the slackware installation disc to start the system.

Note: If you are using a scsi hard disk, use the scsi. s parameter to start the system.

After using root to enter the boot system of this CD, we mount the linux/partition on our hard disk.

Use the following command to mount

Mkdir/mnt/root mount/dev/sda1/mnt/root note: my hard disk is scsi and the/partition is on the sda device, so I use mount/dev/sda1 to mount/partition. Your hard disk and partition may be different from mine. You need to modify the mount command on your own.

Then we use vi to edit the shadow file on the hard disk.

Vi/mnt/root/etc/shadow

We will see a picture similar to the following.

Modify the content of the first line as follows:

Root: 12941: 0 :::::

In fact, the content between the first colon and the second colon after the root is deleted.

Then we can save and exit and restart the system with reboot.

Summary

 
The first method is not to use a CD, which is easy. You can also change the password. However, if the lilo startup screen does not appear, it will not be easy.

The second method requires a CD to start the system, which is more complex. But it can be used as a supplement when there is no lilo startup screen. However, the second method can only simply clear the password. Remember to set the password after the next startup.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.