Raspberry Pi SSH settings without the official imager

Ats
2 min readNov 26, 2023

--

I needed to set up WiFi and SSH settings without the official imager. This is the note of what I did.

Photo by Compare Fibre on Unsplash

First of all

I’m talking about the OS which is based on Raspberry Pi OS (Raspbian).

Background

In my side project, I needed to set up the WiFi and SSH settings for a custom OS based on Raspberry Pi OS with Balena Eacher. If I use the Raspberry Pi OS, I can use the official imager to install the OS to my Raspberry Pi.

I can set WiFi credentials and SSH settings in advance on the imager. But this time, I needed Balena Eacher to install my OS. Moreover, I needed to connect my Raspberry Pi through SSH. So I started to figure out how to do that.

What I did

Super simple. I just followed the document provided by the Raspberry Pi team.

In my Mac development environment, there are my procedures.

First, I flashed the image to my SD card with Balena Eacher and inserted the SD card into my laptop. I checked the connection with the following command.

RPI_BOOT="/Volumes/path/to/your/boot/directory"
[ ! -d "$RPI_BOOT" ] && echo "ERROR: RPI boot directory not found"

Then, with the path to the boot directory set up, I configured the default user and password for SSH like below.

USERNAME='' # CHANGE: your desired username
PASSWORD='' # CHANGE: your desired password

cat << EOF > "$RPI_BOOT"/userconf.txt
${USERNAME}:$(openssl passwd "$PASSWORD")
EOF

Then I created the file for WiFi credentials in the same directory.

WIFI_SSID='' # CHANGE: your WiFi name
WIFI_PASS='' # CHANGE: your WiFi password
COUNTRY='US' # CHANGE: two-letter country code, see https://en.wikipedia.org/wiki/ISO_3166-1

cat << EOF > "$RPI_BOOT"/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=$COUNTRY

network={
ssid="$WIFI_SSID"
psk="$WIFI_PASS"
}
EOF

Finally, I enabled SSH by creating an empty file.

touch "$RPI_BOOT"/ssh

Afterward, I set the SD card to my Raspberry Pi and plugged it into the power. It should have been connected to WiFi automatically. I opened my WiFi router admin and checked the local IP like below. In this case, the device was named picroft

Then I just connected the IP address through SSH.

That’s it!

--

--

Ats
Ats

Written by Ats

I like building something tangible like touch, gesture, and voice. Ruby on Rails / React Native / Yocto / Raspberry Pi / Interaction Design / CIID IDP alumni

No responses yet