Install Raspbian Stretch Lite Headless ( setup Wi-Fi and activate ssh without access to command line or using the network cable) on Raspberry Pi Zero W
UPDATED December 2018 to work with the new version of Raspbian Stretch.
If you have a Raspberry Pi Zero W (or other model) like me and you can’t connect a keyboard or screen to it. And also the Pi Zero W doesn’t have a ethernet port. You will need to do the setup a bit different.
In this tutorial I will follow all the steps to setup Raspbian Stretch Lite on your Raspberry Pi (Zero W or other) so in the end you can connect to it via SSH.
For this you will need:
- Raspberry Pi (I have Raspberry Pi Zero W)
- A micro SD card — Here we will install the Raspbian Stretch Lite
- Another computer to setup the image, wi-fi password and ssh access. (I use a Mac Book, so if you are on a Windows, probably some steps may change, but it should be something similar)
First of all go to Download Raspbian from official raspberry pi website. I will use the non desktop lite version because I only need access to command line. I don’t need the user interface.
The easier method to install on the SD card is using Etcher. So I will use this method in this tutorial.
- Go here to download balenaEtcher and install it. It’s available for Mac, Linux or Windows. So you should be covered.
- Connect the SD card to your PC
- Open balenaEtcher and choose the image file (.zip) that you just downloaded (The filename is something like this: 2018–11–13-raspbian-stretch-lite.zip).
- Select the SD card you want to write to.
- And click “Flash!”.
- You will see the progress where the Flash! button is located on the image above.
Setup Wi-Fi without keyboard or network access
If you have Raspberry Pi Zero W like mine probably you will need to use some adaptors to connect a USB Keyboard and a HDMI Screen, but in case you don’t have those adaptors or you don’t have a USB Keyboard or Screen you can set-up to connect to your local Wi-Fi network from another computer and after that just pop-in the SD card and power-up the Raspberry Pi and it will automatically connect.
So to do this, after balenaEtcher completed to flash the Raspbian Stretch image to the SD card do the following:
- Detect the mount point of the SD card. If you use osx you can do that with this command
- If you are on Windows check where the SD card is mounted.
In the root of the SD card create a new file named: wpa_supplicant.conf
- In the file you should add something like this:
psk="Your Network's Passphrase"
- country should be your country code. Change if you are outside of US
- ssid is the name of the Wi-Fi network.
- psk is the password of your Wi-Fi Network
- key_mgmt usually it’s WPA-PSK, can have other values like WPA-EAP, but you should be ok with WPA-PSK in most cases.
After you finish this steps your Raspberry Pi will automatically connect to your Wi-Fi when you pop-in your SD card and power-up.
Setup SSH Access
But the problem is that you still can’t access the Raspberry Pi. You will also need to setup SSH access so you can connect to your Raspberry Pi from other computers from the same network.
You will need to have your SD card connected to your computer again and this is a really simple step
- Create an empty file in the root of the SD card named ssh (without dot or extension).
This will enable ssh on your Raspberry Pi so you will be able to connect next time you plug in the Raspberry Pi.
After that I put the SD card into my Raspberry Pi Zero W and plug in the Power cable (the one named PWR) and wait a little bit so the raspberry boot and connect automatically to Wi-Fi.
Connect via SSH
- Find the IP Address of your Raspberry Pi.
In order to connect via SSH to your Raspberry Pi you will need to know the local IP of the Raspberry.
If you have Google WiFi it’s a bit easier.
Just open the app and go to Devices and search for raspberrypi. Select and go to Details to get the IP address.
You can also reserve the IP address so next time you restart the raspberry pi you will have the same IP address and you don’t have to search again the ip address.
Else go to your router settings. Usually this is 192.168.0.1 or something like that. If you don’t know check on your router to find the IP address, username and password. After you successfully connect to your router go to Connected Devices and you will see something like raspberrypi.
Now you have the local IP address of your Raspberry Pi.
Open a Terminal window a type:
pi is the default username on your Raspberry Pi. You will use this for the first time, after that you can change if you want to.
Also make sure you will use the IP address that you just found on the step before.
It will ask you: “Are you sure you want to continue connecting (yes/no)?”. Type yes and hit Enter
After that it will ask for the password. The default password is: raspberry
If you are connected you should see the prompt like this.
Change the default password
As you can imagine all the raspberries have the same username and password by default. You should change your default password right at the beginning with a more secure one. This is a very simple step.
- Just type passwd after you connect to your raspberry using the pi username
- Type the current password: raspberry
- And type the new password two times
Next type you will connect to your Raspberry use this new password.
To be sure that you have the latest packages with all the security fixes up to date you should run:
- sudo apt-get update — To update the list of available packages and last version of each package
- sudo apt-get upgrade — To upgrade the packages to the latest version. Probably the prompt will ask you to confirm. Type Y and hit enter.
That’s it. Now you should have a Raspberry Pi Zero W connected to your local network, accessible via SSH from other computers and with the latest version of packages.