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. wpa config update
Since the /boot partition is accessible by any computer with an SD card reader, wifi configuration is now much simpler.
A skeleton wpa_supplicant.conf file can be as little as:
network={ ssid="YOUR_SSID" psk="YOUR_PASSWORD" key_mgmt=WPA-PSK } Also, since November 2016, SSH is disabled on Raspbian by default. However, it is very easy to enable:
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.
sudo dpkg-reconfigure openssh-server
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
iface default inet dhcp
vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib
vi /etc/default/keyboard
modify XKBLAYOUT="pb" to XKBLAYOUT="us"
diskutil list
sudo dd if=/dev/disk2 of=~/berry/SDCardBackup-17-09-30.dmg
#Then use the this to write the image back to the SD card:
diskutil unmountDisk /dev/rdisk2
sudo dd bs=1m if=~/SDCardBackup.dmg of=/dev/rdisk2
#Once it has finished writing the image to the SD card, you can remove it from your Mac using:
sudo diskutil eject /dev/rdisk2