HowTo: RaspberryPi – SSH and WiFi set before the first boot

By default, SSH access is disabled on a RaspberryPi. If you should start a fresh RaspberryPi for the first time or you have reinstalled the operating system, the login via SSH is not possible at first.
In order to activate this, you first have to log in locally – ie via an attached keyboard, mouse and screen – to the RaspberryPi and activate SSH manually.
On this (local) way you would possibly also enter the login data to bring your RaspberryPi in your own Wi-Fi.
Depending on how well your USB keyboard/screen/mouse is hidden or even generally available, this can be anoying.

How to activate SSH and store your Wi-Fi login data in RaspberryPi without having to log in locally is explained in the following article.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/sicherheitshinweise/


Requirements

Helpful Articles:
Before you can do the Wifi configuration and the activation of the SSH server, you should have prepared the SD card for your RaspberryPI.
RaspberryPi – Setting up for Nerdiys!

Required tools:
-none-

Required material:

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


Open boot partition

After inserting the SD card of your RaspberryPI into your card reader, you should recognize two drives. One of them is not readable for your (Windows) computer, so he gives an error message here and asks you to format this drive. But that does not need to bother you. Of interest in this case is only the other, recognized drive. In this example, the drive “boot (E :)”. Open 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 have to create an empty file called “ssh” in this boot drive.

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

Save WiFi configuration

To set the WiFi configuration (ie SSID and WiFi password) before the first boot, you need to create a text file in your boot drive named:

wpa_supplicant.conf
To do this, right-click on an empty space in your boot drive and then go to “New-> Create New Text Document”. This will create a new text document as shown.
You assign this to “wpa_supplicant.conf” by right-clicking on the file and then “rename”.
As you change the file name extension again, Windows gives you a hint again. You can confirm this message with “Yes”.
Now you have to open the just created and renamed file with a text editor and enter the following text in it.
# Datei wpa_supplicant.conf in der 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 exchange “SSID_EURES_WIFIS” (the name of your WiFis) for the name of your WiFis and “PASSWORD_EURES_WIFIS” for the password of your WiFis. Then you save and close the file.

Configure multiple networks with Raspbian Jessie

# Datei wpa_supplicant.conf in der 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"
}

Inserting the SD card into your RaspberryPi

After you have entered these configurations you can use the SD card again in your RapsberryPI. The next time you boot, the configurations are automatically applied and activated.
The RaspberryPi should connect to the set Wi-Fi and be rechable via SSH.


I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. 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 appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

Leave a Reply

Your email address will not be published. Required fields are marked *