在無頭Pi上為Wifi準備SD卡


176

我需要通過WIFI SSH我的Pi,但是因為它是A型板(不可能使用USB集線器-曾經如此)並且我沒有以太網,所以我無法配置Pi以連接到我的安全wifi網絡。我想將SD卡插入筆記本電腦,並想編輯其中包含wifi配置信息的文件,這樣我的Pi在啟動時會自動連接到我的網絡,因此我可以通過SSH進行控制。由於this answer,我知道如何在無頭系統上啟用SSH。

修改。我一直在搜索,我想知道是否可以在SD卡在我的PC中的情況下編輯文件/etc/network/interfaces,並將其中的所有網絡ssid,psk和wlan0放入其中。這樣行嗎?謝謝

1

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


2

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/


25

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.


-3

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.


2

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...


1

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


270

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.

If you don't wish to store your wifi password in plain text, you can use the wpa_passphrase utility to store the hashed password:

wpa_passphrase «your_SSID»

The utility will prompt for the password, and will return the hexadecimal hash value. Note that this hashed password is stored without quotes in the /boot/wpa_supplicant.conf, eg:

psk=b76dc68cb76bfea7232e32634f859ca760cd8abeee318a346b51d3bde00b8965

Note that the country, ctrl_interface and update_config lines are required in file as created in /boot: if they are missing the system will not connect to the network. The above process can be repeated to correct the omissions.

This process has been tested with both Raspbian and Raspbian Lite as of the November 2018 release.


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.


12

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.


4

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

2

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 [email protected]

the default password is raspberry


-2

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.