Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism to assign user/password on first boot? #53

Open
katettudelft opened this issue Dec 20, 2022 · 4 comments
Open

Mechanism to assign user/password on first boot? #53

katettudelft opened this issue Dec 20, 2022 · 4 comments

Comments

@katettudelft
Copy link

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!)

@carlosperate
Copy link

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

@agoldcheidt
Copy link

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.

@adam-zieba
Copy link

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!

@spanag
Copy link

spanag commented May 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants