HowTo: Raspberry Pi – Set SSH and WiFi before the first boot process

By default, SSH access is disabled on a RaspberryPi. If you start a fresh Raspberry Pi for the first time or have reinstalled the operating system, you will not be able to log in via SSH at first.
In order to activate this, you would first have to log in to the RaspberryPi locally - i.e. using a plugged-in keyboard, mouse and screen - and activate SSH manually.
In this (local) way you would also enter the login details to connect your RaspberryPi to your own WiFi.
Depending on how well you hide your USB keyboard/screen/mouse or generally have it available, this can be tiring.

In the following article I will explain how you can activate SSH and store your WiFi login details in the RaspberryPi without having to log in locally.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you can configure the WiFi and activate the SSH server, you should have prepared the SD card for your RaspberryPI.

The following article describes what needs to be done:
RaspberryPi – setup for nerdiys!

Required material:

In the following list you will find all the parts you need to implement this article.


Open boot partition

After you have inserted the SD card of your RaspberryPI into your card reader, two drives should be recognized. One of the two cannot be read by your (Windows) computer, which is why it issues an error message and asks you to format this drive. But that doesn't need to bother you any further. In this case, only the other detected drive is of interest. In this example, the “boot (E:)” drive. Opens this...
...and you are in the boot partition of your RaspberryPI.

Enable SSH server

In order to activate the SSH server on your RaspberryPI before the first boot process, you must create an empty file called “ssh” in this boot drive.

To create an empty file with the name “ssh”, right-click on a free space in your boot drive and then go to “New->Create new text document”. A new text document will then be created as shown.
You now have to rename this (including the file extension). So “New Text Document.txt” becomes “ssh”.
Since by deleting the file name extension you are deleting an actually important (but in this case unnecessary) part of the file name, Windows will remind you of this again. But since we know what we are doing, this is not a problem and you can confirm this error message by clicking “Yes”.
After you have confirmed the warning, the file has been successfully renamed. The next time you start your RaspberryPI, the SSH server will be activated automatically.

Save WiFi configuration

In order to set the WiFi configuration (i.e. SSID and WiFi password) before the first start, you need to create a text file in your boot drive with the name:

wpa_supplicant.conf

create.

To do this, right-click again on a free space in your boot drive and then go to “New->Create new text document”. A new text document will then be created as shown.
Rename this to “wpa_supplicant.conf” by right-clicking on the file and then clicking “rename”.
Since you change the file name extension again, Windows will remind you of this. You can confirm this message with “Yes”.
Now you have to open the file you just created and renamed with a text editor and enter the following text into it.
# File wpa_supplicant.conf in the boot partition (Raspbian Stretch) country=DE ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="SSID_EURES_WIFIS" psk="PASSWORT_EURES_WIFIS" key_mgmt=WPA- PSK }
Of course, you have to replace “SSID_EURES_WIFIS” (i.e. the name of your WiFi) with the name of your WiFi and “PASSWORT_EURES_WIFIS” with the password of your WiFi. Then save and close the file.

Configuring multiple networks with Raspian Jessie

# File wpa_supplicant.conf in the boot partition (Raspbian Jessie) country=DE ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="NetworkName1" psk="NetworkName1_PASSWORD" id_str="RandomConfigurableIdOfThisNetwork " } network={ ssid="NetworkName1" psk="NetworkName1_PASSWORD" id_str="RandomConfigurableIdOfTheSecondNetwork" }

Insert the SD card into your RaspberryPi

After you have entered these configurations you can reinsert the SD card into your RapsberryPI. The next time you boot, the configurations will be automatically applied and activated.
The RaspberryPi should connect to the set WiFi and also be accessible via SSH.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.