How to Set Up a Headless Raspberry Pi, Without Ever Attaching a Monitor
Raspberry Pis are so convenient because they’re inexpensive and small, but connecting one to its own monitor, keyboard and mouse requires a lot more space and money. If you’re just trying to program on the Pi or use it to control electronics such as lights, motors and sensors, there’s no need to connect it to a display or input devices because you can control the system remotely, using a VNC or SSH client on your main computer. We call this screenless install a headless Raspberry Pi setup.
By default, the Raspberry Pi’s official operating system, Raspberry Pi OS (formerly known as Raspbian), installs with all forms of remote access disabled. But the good news is that you don’t need to connect to a monitor and keyboard in order to turn them on. By following the instructions below, you can create a headless Raspberry Pi that’s ready for remote access before you boot it up for the very first time. If you have a monitor and keyboard on hand, you can also see our guide on How to Set Up a Raspberry Pi for the First Time.
Installing Raspberry Pi OS on Your microSD card
1. Insert a microSD card into your computer. Your card should be 8GB or larger (the lite version of Raspberry Pi OS will use less space). We have a list of the best microSD cards for Raspberry Pi to help you choose one that optimizes performance.
2. Download, install and run Raspberry Pi Imager.
3. Click the Choose OS button. A menu appears.
4. Select your OS. The best choice for most people is Raspberry Pi OS (32-bit). However, if you have a Pi 3 or 4, you can use the 64-bit version which is under “Pi OS (other). There are also other choices.
5. Click Choose Storage and select your card from the menu.
6. Click the settings button or hit CTRL + Shift + X to bring up the settings menu.
A menu appears.
7. Toggle set hostname and change the hostname if you want your device to be named anything other than “raspberrypi.”
8. Toggle enable SSH to on and select “User password authentication.”
9. Set a username and password for your Pi. Note that if you use the password “raspberry” with username “pi,” you may get a warning message when you log in, recommending (but not forcing you) that you change the password.
10. Set your Wi-Fi network’s SSID, password and country. Then click Save. The country usually defaults to “GB” (Great Britain) so, if you are in the U.S., you will have to scroll down a really long way to get the country code you need.
11. Click Write and click Yes if asked whether you are sure you want to continue.
The system will now take a few minutes to download the OS and write it to your card.
When it’s done, you can pop your card into a Raspberry Pi, boot it up, wait a few seconds for it to get onto the network and attempt to log in via SSH, provided that you’re using a Wi-Fi network and both the Pi and your client PC are connected to it.
Editing Wi-Fi on a Prewritten Card
Let’s say you already wrote a card, but forgot to enter the correct Wi-Fi credentials in Raspberry Pi Imager. Or perhaps you moved to a different Wi-Fi network. You can still change the Wi-Fi network, without attaching a screen and keyboard to the Pi.
To setup a Wi-Fi connection on your headless Raspberry Pi, open the microSD card on your PC. Then create a text file called wpa_supplicant.conf, and place it in the root directory of the microSD card. You will need the following text in the file.
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
scan_ssid=1
ssid="your_wifi_ssid"
psk="your_wifi_password"
}
Change the country to “GB” for the UK or to another country code for a different country, and enter your actual SSID and password. Upon boot up, Raspberry Pi OS will log you into that network. However, if you’re on a public Wi-Fi network that requires you to click “Ok” on a splash page before you get Internet, this method won’t work.
Prefer to use Ethernet? If you plug your Raspberry Pi directly to a wired network, you should be able to access it by its name (raspberrypi or raspberrypi.local) without changing any other files.
Direct USB Connection (Pi Zero / Zero W Only)
My favorite way to connect is via a direct USB connection, plugging my Pi Zero W directly into a port on my PC. This method is great, because it works no matter where you are (even if there’s no available Wi-Fi), and it provides both power and a connection to your Pi, over a single cable. However, you can only do this on a Pi Zero or Zero W.
1. Open the file config.txt in the root directory of the micro SD card, and add the line dtoverlay=dwc2 to the very bottom of the file and save.
2. Open cmdline.txt and add the text modules-load=dwc2,g_ether after the word rootwait, and save the file. There are no linebreaks in this file.
3. Download and install Bonjour Print Services from apple.com (if you have Windows). It seems strange that you would need an Apple program to access a Pi from Windows, but this helps your PC see the Pi. Ignore the name; you’re not using this for printing.
4. Connect the micro USB cable to the port labeled “USB” on the Pi Zero. This will not work if you connect to the port labeled “PWR.” However, the “USB” port will also supply power to your Pi, so you don’t need to connect a dedicated power wire.
Read more: How to Set Up a Headless Raspberry Pi, Without Ever Attaching a Monitor