Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to change the root password when you forget it.

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

How to change the root password when you forget it.

#1 Post by edbarx »

Warning:
Hardened installations which prevent interacting with GRUB, the bootloader, are not included, especially, as that can be used maliciously to access systems illicitly.

Note:
Since I have been away from Debian for several years, I did mix some things up. This is why I am re-writing the how-to for the benefit of all.

Method A (Using GRUB):
  1. Turn on the computer.
  2. While GRUB displays its screen, press 'e'.
  3. Edit the kernel line to include at the end: "init=/bin/dash" or your shell of preference but make sure it exists in the installation to be booted.
  4. Press F10 to boot.
  5. You will be presented a dreaded terminal. In that terminal you have root preveleges.
  6. Since you have root privileges, you should be able to use passwd to change the root password.
  7. Run the command and follow the prompts.
  8. Reboot.


Method B (Using chroot):
  1. Boot a Live CD on the computer you need to work on.
  2. Open a terminal and become root.
  3. Mount the root file system of the target installation.
  4. Use chroot to become root on the target installation. If the mounted file system is mounted on /mnt/sda1, the command will be "chroot /mnt/sda1 /bin/bash". You may need to use another shell emulator. Make sure you use one that exists on the the target installation.
  5. Use passwd to change the root password on the target installation.
  6. Exit the chroot with "exit" and unmount the target installation's root file system.
  7. Exit the Live Linux CD.
For commands that have been replaced by systemd, replace them with the new commands and consult the documentation.
Last edited by edbarx on 2020-07-12 15:01, edited 3 times in total.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: How to change the root password when you forget it.

#2 Post by p.H »

Looks like you are mixing two unrelated things up :
- get a root shell from GRUB (does not need chroot nor extra mounts)
- get a root shell from chroot (does not need GRUB interaction)
edbarx wrote:Edit the kernel line to include at the end: "init=/bin/dash".
IMO bash is much more convenient, with completion and history.
edbarx wrote:Mount the root partition as 'rw'
You can skip the remount with rw if you replaced "ro" with "rw" in the kernel command line.
edbarx wrote:The command for chroot is: "chroot /dev/sda1 /bin/dash"
I do not think that chroot accepts a device as the new root.
Also be careful when typing the new password if you use a non QWERTY US keyboard unless the proper keymap was forced in the initramfs.
Last edited by p.H on 2020-07-12 10:02, edited 1 time in total.

User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Re: How to change the root password when you forget it.

#3 Post by edbarx »

I edited the first post in accordance to the feedback from p.H.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

Post Reply