I'm using a Raspberry Pi and I want to install Raspbian on it. I don't have a monitor, mouse or keyboard. How do I install Raspbian headlessly?
1 Answer
You will need:
- A formatted microSD card with at least 16 GB.
- A computer with an Internet connection
- A microSD card adapter (if your computer can't read microSD cards)
Prerequisites on your computer:
- PuTTY (downloadable here) or a similar SSH client
- balenaEtcher (downloadable here) or a similar microSD card flasher. If you're using Linux or macOS, use the
dd
command. - Bonjour (downloadable here)
- The latest version of Raspbian (downloadable here) Note: Don't unzip the ZIP file that you get.
- An IP scan tool
Steps:
Plug in your microSD card to your computer. If it can't read microSD, use an adapter.
Open balenaEtcher and select the ZIP file that you downloaded from the Raspberry Pi Raspbian website. Then, choose the drive you want to flash to. Finally, click Flash. balenaEtcher will flash the OS to and validate your microSD card.
After the validation, the card should automatically unmount. If not, continue to the next step. If it has been unmounted, remove it and plug it back in.
In the boot section of the card, which is the only partition you can access, create a file named
ssh
without an extension. It doesn't have to contain anything. It only has to exist.
Note: The following step is only for Raspberry Pis that can connect wirelessly. If your Pi can't connect wirelessly just plug in an Ethernet cable from your router to your Pi and skip the following step.
Create a file named
wpa_supplicant.conf
in the boot section. Fill it with the following contents replacingyour network
,your password
andyour country code
with your network's SSID, its password and your country code (like US and IN) respectively.ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=your country code network={ ssid="your network" psk="your password" }
Eject your card and plug it into the Pi. Turn it on.
Use an IP scan tool to get the IP address of your Pi. It will be listed under
raspberrypi.local
.Open an SSH client and enter the IP address there. Connect using port
22
. Alternatively, you could log in with justraspberrypi.local
.Open the connection and use
pi
andraspberry
as your username and password respectively.
That's it! You're recommended to change the default password with passwd
, though.
-
1Might want to clarify #4 in the last set: "In the boot section of the card" refers to the first partition, which will be formatted
vfat
and < 200 MB in size. If you cannot readext4
filesystems on your computer (MS Windows cannot by default), then this will be the only partition you can access. Thessh
file does not have to contain something, it just needs to exist. Re #2 "or a similar micro SD card flasher" if you have thedd
command (macOS, linux) you can just use that, there are many examples here and elsewhere.– goldilocks ♦Commented Mar 16, 2020 at 16:13