0

This works to initialize a headless RaspberryPi connected by Wifi (no screen/keyboard never needed attached to RPi):

  1. Get a Raspbian Stretch Lite from https://www.raspberrypi.org/downloads/raspbian/ and write it to the micro SD card with Win32diskimager or Etcher

  2. Add an empty ssh file in the boot partition

  3. Boot on Linux (or boot a Linux VM on Windows), or use Linux File Systems for Windows in order to edit /etc/network/intefaces and add:

    auto lo
    iface lo inet loopback
    
    allow-hotplug wlan0
    iface wlan0 inet dhcp
    wpa-ssid "MyRouter"
    wpa-psk "92dc84ee7e7032be9142828023912e77"
    
    allow-hotplug eth0
    iface eth0 inet dhcp
    

This works, I've done it many times in the past years.

Problem: for a Windows user, step #3 is not very convenient. An alternative would be to initially connect via ethernet cable, SSH with putty, and edit /etc/network/intefaces with nano, but it's not very handy too, because it requires to connect the RPi to the router with a cable.

Question: which method would allow to initialize a headless Raspberry Pi, including the Wifi ssid/password setting, 100% from Windows?

I see a few options:

  • A) Would there be a way, on a fresh Stretch Lite install, only by modifying files in the boot partition (accessible from Windows), to configure Raspbian to use a file intefaces in the boot partition instead of the usual /etc/network/interfaces ?

  • B) Would there be a way to put a script copyinterfaces.sh in the boot partition:

    #!/bin/bash
    sudo cp /boot/interfaces /etc/network/interfaces
    

    that would be launched on the first boot of the RPi? Then we could put both the intefaces file (written in the boot partition - easy from Windows) and the copyinterfaces.sh file in the boot partition, and during the first boot, the boot partition's interfaces file would be copied to /etc/network/interfaces

  • C) another idea?

Once again, the goal is: to be able to set up a headless RPi connected by wifi, without using a keyboard/screen/ethernet cable ever, 100% from Windows, so that we can SSH with putty and never have to boot Linux (some users don't have any Linux installation), and never have to use an ethernet cable.

2

See Headless Raspbian WiFi Setup in How to set up networking/WiFi

Specifically Raspbian checks the contents of the boot directory for a file called wpa_supplicant.conf, and will copy the file into /etc/wpa_supplicant, replacing any existing wpa_supplicant.conf file that may be there. The file in the boot directory is then removed. This can be used to enable headless setup.

NOTE the etc/network/intefaces you listed is obsolete and is not needed. Even in 2015 it would have been poor practice but it has been replaced by dhcpcd which is far more robust.

  • Yes. (I don't use Windows, but it certainly works - you may need to use LF line endings rather than CR/LF which can be done with Notepad) – Milliways May 19 at 10:28
  • See the link for sample files. – Milliways May 19 at 10:30
  • @Basj If you have another question, ask another question properly. And no, don't replace those paths. wpa_supplicant != wpa_supplicant.conf. The paths are part of the configuration, they don't refer to the configuration file itself (which would be a bit non-sensical). Also, that file is moved before it is used ("Raspbian checks the contents of the boot directory for a file called wpa_supplicant.conf, and will copy the file into /etc/wpa_supplicant"). – goldilocks May 19 at 14:36
1

Additional information to the accepted answer:

  1. Write the Raspbian Stretch Lite image to the SD card

  2. Create a ssh empty file in the boot partition

  3. Create a wpa_supplicant.conf file in the boot partition containing:

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=FR
    network={
      ssid="MyRouter"
      psk="the_password"
    }
    
  4. Boot the RPi and connect it via SSH (for example with putty.exe from Windows). It works, 100% from Windows!

Important note: I've tried with only a wpa_supplicant.conf file containing only:

network={
  ssid="MyRouter"
  psk="the_password"
}

but it did not work; the other lines (update_config...) seem mandatory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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