My Blog

Reset Password on Raspbian Buster

Author: Dmitry Klionsky | Created: 2020-05-16

I recently replaced my laptop, changed ssh key and, as it happens, forgot the password, so I can’t ssh to Raspberry Pi any more.

TL;DR

Here are quick steps how to reset the password. Later I will describe what they mean and add some more advanced commands.

 rw init=/bin/sh
# passwd pi
New password:
Retype new password:
passwd: password updated successfully
# sync
 rw init=/bin/sh

If it’s everything you needed you can stop reading.

rw

 rw init=/bin/sh

The rw flag mounts the root partition / as read-write. If you omit it, the root partition / will be read-only and changing password will fail:

# passwd pi
Enter new password:
Retype new password:
passwd: Authentication token manipulation error
passwd: password unchanged

To remount it as read-write run:

# mount -o remount, rw /
EXT4-fs (mmcblk0p2): re-mounted.

init=/bin/sh

The init flag specifies the program to run as the Init process, i.e. the first process to be run. Here we replace the default /sbin/init, which is responsible for running all the init scripts with /bin/sh, which runs a simple shell.

/boot/cmdline.txt

The file cmdline.txt needs to be edited back, but it’s on the /boot partition, which is not mounted by default. Still, it’s possible to do it without moving the SD card around.

# blkid
/dev/mmcblk0p1 ... LABEL="boot" TYPE="vfat"
/dev/mmcblk0p2 ... LABEL="rootfs" TYPE="ext4"
# mount -o rw /dev/mmcblk0p1 /boot
# nano /boot/cmdline.txt
 rw init=/bin/sh
# sync /boot
# umount /boot

References