How to set up your Raspberry Pi for WiFi without connecting a screen or keyboard to it (imager tool, recommended)

This is now the quickest and easiest way to set up a new Raspberry Pi image that you can log into over Wifi. This works completely without the need for connecting a display, keyboard or ethernet cable to your Raspberry Pi.

On your computer, download and install the Raspberry Pi imager directly from raspyberrypi.org for your platform. 

Insert a 4GB or larger SD card into your computer that you are ok with to completely erase.

Open the Raspberry Pi Imager that you just installed and 

- Choose Raspberry Pi Device > NO FILTERING

- Choose OS > Raspberry Pi OS (other) > Raspberry Pi OS Lite (64-Bit)

Note if you use a Raspberry Pi Zero W, not the Zero 2 W, then use the 32-BIt image.

Note that we are installing the Lite image instead of the Full, as we are not needing the graphical environment and all its dependencies.

- Choose SD Card > Select the inserted card

- Click Next

- Click 'EDIT SETTINGS'

Fill in the hostname.  If you are using this Raspberry Pi for streaming Airplay music, the hostname is what will show up as the speaker name.

Fill in the Username and Password.  A Linux user account for these will be created which we can then use to login to the Linux command line.

Fill in your WiFi name (SSID) and Password that you want this Raspberry Pi to connect to.  This needs to be an existing Wifi in your surrounding. (For creating your own WiFi and use the Raspberry Pi as an Access Point, look at these instructions).

Then set your locale.

Change to the SERVICES tab and click 'Enable SSH' with password authentication.

 

- Click SAVE

- Click 'YES'

- Click 'YES' on the Warning popup.  The Imager will now write to the SD card.

 

Raspberry Pi Imager

Once completed, close the Raspberry Pi Imager and remove the SD card and insert it into your Raspberry Pi.  When connecting power to the Raspberry Pi, it will now already connect to your WiFi after booting if you executed the above steps correctly. Note that this first boot takes longer than subsequent boot ups.  Give it 5 min at least.  The Raspberry Pi will reboot a couple of times on first boot. 

You can then connect to it using the following command from your computers terminal. Replace 'theHostname' with what you entered as the hostname above (in our example that's poolside-zero2).  Keep the .local

ssh -lpi theHostname.local

If this is the first Raspberry Pi that you log in with this hostname, this will work. On your subsequent Raspberry Pis, your computer will recognize that the Raspberry Pi hardware has changed, but has the same name and give you an error like this:


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for raspberrypi.local has changed,
and the key for the corresponding IP address
2600:1700:3ec0:8cb8:803:4697:f8cf:fedf
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:dapIrjOu2LTHta+F6o3OzHzQAcec+V+CICfTmGIg65I.
Please contact your system administrator.
Add correct host key in /Users/gany/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/gany/.ssh/known_hosts:11
ECDSA host key for raspberrypi.local has changed and you have requested strict checking.
Host key verification failed.

If this happens, the fix is easy, simply delete one line out of the file ~/.ssh/known_hosts.  Notice how the error in my case above shows kown_hosts:11, meaning that in my case, I have to delete line number 11.

You can do this directly from the command line with this command:

sudo sed -i '' '11d' ~/.ssh/known_hosts #deletes line 11

You might have to repeat this step several times to delete several entries from known_hosts. 

After that, if you retry to log in, you should get to the login prompt. The default login for a Raspberry Pi is:

Login:  (use the username you specified in the pi imager)
Password: (use the pw you specified in the pi imager)
It is also a good idea to bring the Raspberry Pi image up to the latest state, despite you just downloaded it.  The image might have been created some time back. You can also install a few command line tools that you generally install, and do all that using a one liner that allows you to walk away from your computer for 10 minutes...
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y vim

Leave a comment

Please note, comments must be approved before they are published