An easy yet challenging task
A straightforward yet challenging task is to deal with a QR code scanner Kiosk positioned at the entrance of a container port. The Kiosk utilizes a Raspberry Pi 3B+ (RPi) as a sensor control, connected to a LAN network and utilizing GPIOs. I was tasked with changing the IP address of a spare RPi to match that of a faulty one, enabling a quick resumption of the kiosk’s functionality. However, the login credentials (username and password) were lost.
Approaching the Problem
Initially, I assumed that the project’s programmer had continued using the default username “pi.” While it seemed impossible to retrieve the original password, changing to a new password remained my last resort. I researched various methods online and discovered one potential solution. By temporarily adding ‘init=/bin/sh’ to the end of ‘/boot/cmdline.txt,’ the RPi can be forced to boot into a root level console mode, allowing the password for the ‘pi’ user to be changed.
Instructions
1. Take out the SD card from the RPi and insert it into a SD card reader on my Window 10 PC. A boot drive will appear.

2. Edit the /boot/cmdline.txt file using an editor like notepad++ and temporarily append the command init=/bin/sh at the end of the existing content. Ensure there is a space before init=/bin/sh without starting a new line.

I discovered the following information, and I have appended “init=/bin/sh” to the cmdline.txt file.
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=0c9aa21f-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait init=/bin/sh
The /boot/cmdline.txt file is a configuration file utilized in the boot process of the RPi. It includes command-line parameters and options that get passed to the Linux kernel when the system starts up.
Adding init=/bin/sh to the /boot/cmdline.txt file in RPi is a method to boot the system into a single-user mode with a root shell prompt.
3. Reinsert the SD card into the RPi while having a keyboard connected to a USB port. Then power on the RPi.
4. Depending on your splash screen settings, you should observe a message similar to either /bin/sh: 0: can’t access tty: job control turned off or a full screen of text messages which can be ignored.

5. Press the [Enter] key to get a # prompt, then enter the following commands exactly as shown. If any messages appear during you enter the following commands, simply press the [Enter] key to get a # prompt again.
mount -o remount, rw /
passwd pi
sync
exec /sbin/init

Please ensure that there is proper spacing between characters and words. In the command “passwd pi,” the username assumed to be used by RPi is “pi.” By executing this “passwd” command, you will be prompted to enter a new password twice.
When the above exec /sbin/init command is entered, the RPi will reboot.

6. After successfully logging into the RPi, remove the “init=/bin/sh” from the /boot/cmdline.txt file. Subsequently, reboot the RPi once again.
Result
Success! It works. I am able to access the RPi using the username ‘pi’ and the new password. I must admit, if the username was changed to something other than ‘pi’, the likelihood of successfully logging into the RPi would be quite low.
Further explanation for the commands
(1) mount -o remount, rw /
This command remounts the root file system (“/”) as read-write(“rw”), allowing write access to the file system.
(2) passwd pi
This command changes the password for the user “pi.” After executing this command, you’ll be prompted to enter a new password twice for the user.
(3) sync
This command synchronizes changes to the file system with the underlying storage device. It ensures that any pending changes are written to disk before proceeding.
(4) exec /sbin/init
This command continues the boot process and launches the regular user interface or shell.