We are all human beings and do not work like flawless creatures of artificial intelligence, we are prone to make mistakes and forget things. Although, sometimes we forget crucial information which might be essential to our daily life, like the root password of our server. For a sysadmin it can be a real disaster if s/he cannot log into the server. What can you do if this happens with you? Follow our easy step by step instructions, which will solve this matter. Save this list and you will never have to stress about the lost or forgotten password again.
First of all, if you forget the root password of your Debian system, do not panic! We have several solutions that you can execute with ease.:
Password Reset Using “Grub”:
- Restart your server and press “Shift” for a long time during the boot, in order to access Grub.
- Press the down arrow and choose “recovery mode”
- After this, the booting process starts and you will see the recovery mode. With the aid of the down arrow, choose the “root” line and press Enter.
- Now, write this command: passwd (insert your username here) .
- The program will ask for a new UNIX password, and its confirmations.
- Finally, enter reboot, and you are all set :)
Boot into Grub, select “single user” but do not press enter.
- Press “e” to go into edit mode.
- Scroll down to the kernel line you will boot from, it starts with “linux /boot/vmlinuz-…….”
- Scroll to the end of that line and press “space” once and type init=/bin/bash
- Press Ctrl X to boot
# Remount / as Read/Write
mount -rw -o remount /
# Change the root account password with:
# Change any other account password with:
passwd (insert the username here)
# type new password, confirm and hit enter, then reboot.
Password reset with Live CD or USB
- Boot the server from a portable data medium.
- Attach the drive.
- Press ALT+F2 key combination to view the “running applications” window.
- Write gksu nautilus command to run the taskmanager as root.
- Open the root directory of the attached driver and enter to the etc directory
- Look for the file called “shadow” and create a backup just for the sake of security.
- Edit the original file: Search the user who forgot the password.
- It should look like the following:
- Delete the characters between the first and second colon, which will erase the password of the user.
- As a second option, you can change the characters.
- Save the file and reboot the server.
Resetting the root account password in a Container
This works flawlessly on Ubuntu 14.04.4 LTS:
- In the script that rebuilds the container (which should be running on the “host”), add these lines:
- echo -e “$PASS\n$PASS” | sudo docker exec -i passwd
We hope these tips will help you and you do not have to worry about accessing your server again. Do you have any other solutions to handle this situation? Don’t hesitate, share your tricks with us anytime!