dockerpi icon indicating copy to clipboard operation
dockerpi copied to clipboard

Mechanism to assign user/password on first boot?

Open katettudelft opened this issue 1 year ago • 4 comments

Hello!

So for security reasons, Raspberry Pi OS images no longer come with a pre-configured pi user - see here:

https://www.raspberrypi.com/news/raspberry-pi-bullseye-update-april-2022/

The good news is, you can still do headless configurations on a physical Pi by placing a userconf file in the /boot partition.

Is there a mechanism to do this in dockerpi?

(I realise that the repo hasn't been updated for a while - I hope it's still maintained, it seems like a really useful tool!)

katettudelft avatar Dec 20 '22 16:12 katettudelft

If anybody figures out how to configure this I would also be interested to in a solution.

carlosperate avatar Jan 16 '23 17:01 carlosperate

Hi there, I use a little script before running the Rasberry Pi OS through dockepi:

#!/bin/bash
#Args
img=$1

#Usage checks
if [[ -z $img ]]; then
  echo "Usage: $0 imagefile.img"
  exit -1
fi
if [[ ! -e $img ]]; then
  echo "ERROR: $img is not a file..."
  exit -2
fi
if (( EUID != 0 )); then
   echo "ERROR: You need to be running as root."
   exit -3
fi

#Creating the mount point
losetup loop55 -P $img
#Mounting image boot partition
sudo mount /dev/loop55p1 /mnt
#Creating username and password into userconfig file
echo 'berryboot:$6$uE1YmGMLJIuYRDA6$7uggLlPOnrfoFczREehC9C.rHVe2N5QQfK5Tbuio1bRAgob6/6j1iN8QyrJkvv4rfVbhsFICI.cPmKe.rT8Qi.' > /mnt/userconf.txt #Adding custom user account only for Raspberry Pi OS Lite
echo ""
#Unmounting image boot partition
sudo umount /mnt
#Detaching the mount point
sudo losetup -d /dev/loop55
echo ""
echo "-------------------------------------"
echo "==== DONE! IMAGE READY ===="
echo "-------------------------------------"
echo ""
sync

If you put that code into a file named "add-username", it will work by executing sudo bash add-username Raspios.xx.xx.img. Note: replace "berryboot" and password with your own username and password, if you do not change them, you can use berryboot as username and password then.

agoldcheidt avatar Jan 27 '23 19:01 agoldcheidt

Thank you for the scrip @agoldcheidt but it does not work for me. Even if the file userconf.txt is created and moved to the /mnt

I double-checked if the file is correctly passed to the /mnt directory and everything seems to be ok including my username and password in the file.

But the Raspbian OS is not accepting these credentials. Any ideas? :)

Thanks!

adam-zieba avatar Mar 03 '23 21:03 adam-zieba

Another way to set an user, passwd, etc. is to override init=/bin/sh in the kernel command line. Instead of systemd the OS will start just a root shell, from which (simple) changes can be done. Don't forget to sync after the changes, because poweroff won't work since systemd is not running and exit will of course panic the kernel, since init=sh exited. Source: https://unix.stackexchange.com/questions/105279/resetting-password-of-another-linux

spanag avatar May 30 '23 06:05 spanag