I need to SSH my Pi over wifi but because it is a model A board (using a usb hub is not possible - ever) and I have no ethernet, i can't configure the Pi to connect to my secured wifi network. I want to have the SD card plugged into my laptop and I want to edit a file with the wifi configuration information in it so my Pi will connect to my network automatically at start-up so I can then SSH it to get control. I know how to enable SSH on a headless system thanks to this answer.

Edit. Ive been searching around and I'm wondering if I'm able to just edit the file /etc/network/interfaces while the SD card is in my PC and put in all the network ssid, psk and wlan0 stuff in it. Will this work? Thanks

  • You are faced with quite a predicament there. I would suggest using a USB LAN temporarily to connect over SSHS. Most drivers are included for those. Insert your WiFi and then follow this answer to set up your WiFi on the Pi. After wards you reboot, unpluggin the LAN and boot in using Wifi. It should auto connect within a few minutes. – ppumkin Oct 22 '13 at 8:29
  • 2
    Low cost way to set up is to use a usb-serial adapter to connect to the serial on the GPIO header. You don't even need to enable ssh to do this – John La Rooy Oct 23 '13 at 5:36
  • see my answer [here][1] for an alternative method [1]: raspberrypi.stackexchange.com/a/31397/30719 – memebrain May 9 '15 at 21:30

11 Answers 11

up vote 180 down vote accepted

There are some great answers here, but many are out of date. Since May 2016, Raspbian has been able to copy wifi details from /boot/wpa_supplicant.conf into /etc/wpa_supplicant/wpa_supplicant.conf to automatically configure wireless network access:

If a wpa_supplicant.conf file is placed into the /boot/ directory, this will be moved to the /etc/wpa_supplicant/ directory the next time the system is booted, overwriting the network settings; this allows a Wifi configuration to be preloaded onto a card from a Windows or other machine that can only see the boot partition.

The latest update to Raspbian - Raspberry Pi, 2016-05-13

Since the /boot partition is accessible by any computer with an SD card reader, wifi configuration is now much simpler.

A typical wpa_supplicant.conf file is:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
    key_mgmt=WPA-PSK
}

Replace «your_ISO-3166-1_two-letter_country_code» with your ISO Country Code (such as CA for Canada), «your_SSID» with your wireless access point name and «your_PSK» with your wifi password.


In addition, you may wish to add Secure Shell (SSH) access to your headless Raspberry Pi. SSH is disabled on Raspbian by default for security reasons. You can enable it by creating a file called /boot/ssh:

For headless setup, SSH can be enabled by placing a file named 'ssh', without any extension, onto the boot partition of the SD card. When the Pi boots, it looks for the 'ssh' file; if it is found, SSH is enabled and then the file is deleted. The content of the file doesn't matter: it could contain either text or nothing at all.

SSH (Secure Shell) - Raspberry Pi Documentation

If you enable SSH access, you should change the password of the standard pi user as soon as possible. As the default password (raspberry) is widely known, your Raspberry Pi is effectively open to everyone on your network until you change the password. You can do this with the passwd command.

  • 2
    There are two restrictions for this solution (tested with 2016-09-23 images): 1. The file must be formatted with Linux style line endings (LF instead of CR LF). 2. It did not work with the Raspbian light image on my Raspberry Pi 3. – user2154065 Nov 23 '16 at 20:24
  • 1
    Now I've got a couple of Raspbian Lite machines running, I'm pretty sure my comment was wrong: wpa_supplicant is included, or can be easily installed. – scruss Mar 4 '17 at 3:34
  • 4
    @kleinfreund don't include the passphrase in clear text. Run "wpa_passphrase SSID" (with your SSID) and enter the passphrase when prompted. Copy the output into your wpa_supplicant.conf file, removing the line that includes the cleartext and leaving just the hashed version. (You can do this on a different system so you have the file ahead of time when setting up your micro SD for the Pi.) – Peter Hansen Jul 12 '17 at 0:09
  • 4
    @scruss - your answer is almost correct, please add this line to the wpa_supplicant.conf sample above: ctrl_interface=/var/run/wpa_supplicant I just tried on a new Zero W with Raspbian Strech Lite – ctekse Sep 5 '17 at 20:36
  • 1
    The ctrl_interface line enables a directory for unix sockets used by the wpa_cli tool to communicate with wpa_supplicant. The canonical reference file for all the options in the file is w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf – Dave X Nov 25 '17 at 6:22

Some specific Instructions:

Contents of /etc/network/interfaces:

auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    post-up ifdown eth0
iface default inet dhcp

Contents of /etc/wpa_supplicant/wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YOUR_SSID_HERE"
    psk="YOUR_SECRET_PASSPHRASE_HERE"
    id_str="SOME_DESCRIPTIVE_NAME"
}

Honest. Those two files, with given contents are what I use on all my pi's. They boot and immediately connect to my wireless router. DHCP negotiation provides an address, and my router resolves the hostname to the proper IP address. Make sure to name each PI appropriately via /etc/hostname.

The weirdness in the interfaces file in the trailing iface default... is needed, otherwise the wireless WPA connection won't come up.

The wpa_supplicant.conf file can have multiple network={ entries too, I used to take my pi to work... plug it in and voila, it connected automagically there too, work's configuration was a bit more convoluted though. Included here as an example, add/replace the following in the wpa_supplicant.conf file:

network={
    ssid="THE_OFFICE"
    scan_ssid=1
    key_mgmt=WPA-EAP
    eap=PEAP
    identity="WORK_USERNAME"
    password="WORK_PASSWORD"
    phase1="peaplabel=0"
    phase2="auth=MSCHAPV2"
    id_str="SOME_DESCRIPTIVE_NAME"
}

Essentially, it scans the wpa_supplicant.conf file and connects to the first network it finds that matches. Very handy. It's possible to make it connect to any 'open' network automatically this way too. Not the smartest thing to do, but doable.

  • I need to have a static ip also as its headless and i wont be able to ssh it without knowing its ip address. I currently have id_str="home" in wpa_supplicant.conf and iface home inet static (static ip info underneath this)in the interfaces file, this gives me a static ip but im not sure if this is the best way to have it set up and its a bit confusing to set up(and i get a error "Cannot find device "home"" on boot). – 11chubby11 Oct 30 '13 at 10:21
  • 1
    I use dyn.com (or dyndns.com) to allow a proper name to access my pi(s), use ddclient to automatically set the name to the proper address. Alternately, use your router to specify a static dhcp address, much more useful. I also use upnpcd to dynamically set up upnp settings to allow me to connect to my systems from outside my network, no static IP's ever needed now, it sets itself up where-ever it is. (iface stanza can only have lo/eth0/wlan0/default as option, 'home' won't work) – lornix Oct 30 '13 at 10:26
  • How can I add /etc/network/interfaces in the SD boot? Just put it anywhere and it will copy it? – denislexic Aug 31 '17 at 21:31
  • Basically a comment to the answer by lornix - whose solution I used successfully - since I don't have rep to write comments. In order to edit the root file system, you need to mount the second partition, not the first, boot partition. I did: sudo mount /dev/sdc2 /mnt after which I could edit files under the /mnt root, i.e. /mnt/etc/wpa_supplicant/wpa_supplicant.conf and /mnt/etc/network/interfaces and /mnt/etc/hostname (again using sudo). When done, cd out of the /mnt hierarchy, and do sudo umount /mnt You can then insert the SD-card in the Rπ and boot. Note that this requires a Linux machine, – Ketil Malde Feb 12 at 19:32

Since November 2016 SSH has been disabled by default in standard Raspbian images for security reasons.

To re-enable it, create a blank file called either ssh or ssh.txt on the sd card boot folder ( fat32 partition accessible from windows)

To preconfigure the wifi settings, you also create a file called wpa_supplicant.conf there containing:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={ 
ssid="MySSID" 
psk="MyPassword" 
}

Both these files can be created on windows, and edited using notepad.

Then insert the SD card into the pi, and you should be able to SSH right in.

  • Nice to see they've simplified the setup greatly! Great Answer! – lornix Feb 19 at 19:09

You can use the interfaces file. Load it up with all the network information and put it in a thumb drive and reboot the RPi with that. The RPi takes the settings and sets up the WiFi without the need for extra hardware or a monitor.

After that you can SSH into Pi and install VNC to get a GUI. If you want a step by step instruction for it, check out Option 3: Connect with WiFion http://www.dexterindustries.com/BrickPi/getting-started/using-the-pi/

  • Couldn't get this to work. Cant find any other info on the internet about this way of setting up wifi. – 11chubby11 Nov 1 '13 at 2:41
  • Forgot to mention the script used to automate this. Here it is – karan May 14 '14 at 6:31

You can also configure an SD card that will automatically install Rasbian with a preconfigured WiFi connection on your Raspberry pi (Raspberry Pi headless setup). This allow your pi to be justconnected to power for its first boot.

Step 1: Download Noobs Get and unzip the latest Noobs software (version Offline and network install) on https://www.raspberrypi.org/downloads/

Alternative : direct link to the file : http://downloads.raspberrypi.org/NOOBS_latest

At that time of writing, the latest NOOBS version is 1.4.0

Step 2: Headless configuration In the os/ directory, delete every other folders than rasbian/. In fact you should have only one other folder named Data_Partition.

In the rasbian/ folder, edit the flavours.json file. You should see following:

{
  "flavours": [
    {
      "name": "Raspbian - Boot to Scratch",
      "description": "A version of Raspbian that boots straight into Scratch",
      "supported_hex_revisions": "2,3,4,5,6,7,8,9,d,e,f,10,11,12,14,19,1040,1041"
    },
    {
      "name": "Raspbian",
      "description": "A Debian wheezy port, optimised for the Raspberry Pi",
      "supported_hex_revisions": "2,3,4,5,6,7,8,9,d,e,f,10,11,12,14,19,1040,1041"
    }
  ]
}

Delete the “Raspbian – Boot to Scratch” part, so the file should look like this at the end:

{
  "flavours": [
    {
      "name": "Raspbian",
      "description": "A Debian wheezy port, optimised for the Raspberry Pi",
      "supported_hex_revisions": "2,3,4,5,6,7,8,9,d,e,f,10,11,12,14,19,1040,1041"
    }
  ]
}

Edit the recovery.cmdline file in the root NOOBS directory and append silentinstall to the arguments list. The file should look like this at the end:

runinstaller quiet vt.cur_default=1 elevator=deadline silentinstall

Step 4 (optional): Configure custom Keyboard layout and Language If you want to change the default keyboard layout (us) and/or default language (default is ‘us’) append lang=XX keyboard=XX in the arguments list of the recovery.cmdline file (XX should be replaced by your language and keyboard code, which could be fr, de, … Default is us).

The file should look like this at the end:

runinstaller quiet vt.cur_default=1 elevator=deadline silentinstall lang=fr keyboard=fr

Step 5 (optional): Configure Wifi Noobs Config is a tool that will copy/past some files just after the installation of Rasbian. Among many other things, this tool allows you to pre-configure Wifi on your Pi. This nevertheless assumes that the wifi dongle you use is directly supported by Raspbian.

First thing is to download Noobs Config on GitHub (https://github.com/procount/noobsconfig/archive/master.zip)

Then unzip noobsconfig.zip and :

  • copy “customise.sh” in the root directory of your Noobs files

  • copy “os/Rasbian/partition_setup.sh” to your “os/Rasbian/” directory of your Noobs files.

  • create a folder named “wifi” under “os/Rasbian/”

  • copy “Examples/Rasbian/wifi/wifi/wpa_supplicant.conf” to
    “os/Rasbian/wifi/” directory of your Noobs files.

  • copy “Examples/Rasbian/wifi/Raspbian_root.txt” to “os/Rasbian/”
    directory of your Noobs files.

Last thing is to configure your wifi ssid and psk (password) in wpa_supplicant.conf :

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="MyNetwork"
psk="MyPassword"
}

Step 5 (optional): Change the default password Even if this step is optional, it’s highly recommended to change the default password of your Rasbian setup.

Edit the os/Rasbian/os.json file. It should look like this :

{
  "name": "Raspbian",
  "version": "wheezy",
  "release_date": "2015-02-16",
  "kernel": "3.18",
  "description": "A community-created port of Debian wheezy, optimised for the Raspberry Pi",
  "url": "http://www.raspbian.org/",
  "username": "pi",
  "password": "raspberry",
  "supported_hex_revisions": "2,3,4,5,6,7,8,9,d,e,f,10,11,12,14,19,1040,1041"
}

Let’s change the default password on the line 9.

Step 5: Copy files on your SD card and boot your Raspberry pi Copy/past files on a FAT formated SD card.

Step 6: Boot and connect Boot on our SD card, after a few minutes (depending on your SD card, the installation process can take more than 30 minutes) and connect to your Pi via SSH.

That it...

  • These instructions look promising, but as of NOOBS v1.9.2 there's no flavours.json file in the os/Raspbian directory. Since the main reason to edit it was to remove an alternate version, I'm thinking it's safe to simply skip that step when not needed. – natevw Aug 21 '16 at 16:11

As of RASPBIAN STRETCH you must include ctrl_interface and update_config in wpa_supplicant.conf

To get wifi with ssh on boot do these simple steps on your SD card:

  1. touch /<sd mount point>/boot/ssh
  2. nano <sd mount point>/boot/wpa_supplicant.conf

With the contents:

country=AU  #omit if US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="YourNetworkSSID-1"
    psk="passwordOne"
}
  1. Unmount SD card, put in pi, boot up pi

The process for headless setup has slightly changed for Raspbian Stretch and newer versions of RetroPie.

inside of boot directory...

touch ssh

nano wpa_supplicant.conf

add this to wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
    ssid="YOUR_NETWORK_NAME"
    psk="YOUR_PASSWORD"
    key_mgmt=WPA-PSK
}

unmount sd card and insert in pi for boot up

give it a minute and find your pi's ip address

ssh into the pi

ssh pi@pi-ip-address

the default password is raspberry

You need to edit the wpa_supplicant.conf file on the sdcard (it's in /etc or /etc/wpa_supplicant depending on your distribution version). The format of the file is explained here: http://linux.die.net/man/5/wpa_supplicant.conf

  • But if wireless drops out it wont auto reconnect using the basic settings. It requires you use manual mode and roaming with extra configuration files. – ppumkin Oct 22 '13 at 12:44
  • Well it should be enough to setup, right? As it will definitely connect when wpa_supplicant starts if the network is available. I also thinks wpa_supplicant should automatically reconnect if you loose network. – hogliux Oct 22 '13 at 13:01
  • Further to my last comment, I'd like to add that I've used this method myself on a raspberry model A with the newest debian. – hogliux Oct 22 '13 at 13:07
  • WPA Supplicant will not reconnect if you use AUTO, you need to use STATIC with ROAMING and define SSID to connect to... which is a bit tricky to set up. – ppumkin Oct 22 '13 at 15:28

I have created a shell script tool (unfortunately only runs on Linux), it automates the entire process of downloading the latest Raspbian image, unpacking the image, embedding the wi-fi and ethernet settings (provided by the user) in the image, repack the image and burn it on the SD card. When you boot your Pi with the SD card, it straight away connects with your network. The script also has the capability to searching for a freshly configured Pi on the network.

You can directly connect a Wi-Fi dongle with your Pi, use the RaspImgConfig.sh script to embed the Raspbian Image with wi-fi credentials and burn the image on the card. No need for any monitor, mouse or keyboard.

Youtube video of using the tool: https://youtu.be/WdYb1L2WzjM

Regards, Subhajit Ghosh

You can set up your pi to work with a password protected wifi and automatically enable ssh without booting the pi, with config files in the /boot partition.

I used this for my AIY and scanned the network using nmap to find my pi.

From there you can just connect to the pi.

  • You should at least explain the file names needed and their contents, as well as a link to further information. – Steve Robillard May 14 at 22:48

I think all these answers are missing the point that the RPi model A HAS NO Ethernet, no wi-fi, so no matter what you do, unless you get an external dongle, you wont be able to connect to the RPi through ssh.... your best bet is either to use it directly on a TV or to use it through the serial port on the headers, or as I said, get an external dongle for wifi.

  • 5
    I think it's implied that he is already using one. One would assume that the OP is aware that he cannot connect to a wireless network without some sort of adapter. – Impulss Dec 8 '13 at 22:51

protected by Darth Vader Oct 7 at 20:58

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.