Update July, 2023:
Nowadays, I would recommend using the “Raspberry Pi Imager”. You can download it here: https://www.raspberrypi.com/software/. It’s much faster than doing all the manual work. Just make sure that you select as OS the minimal version without any desktop.
The tool can download the image itself, format your SD-card and install it correctly on it. Also it has options for presetting the wifi connection and other stuff.
What is special about this minimal setup?
Basically, you could just install any of the preconfigured Linux distribution available. However, these often include features you do not necessarily need and also setup is often dependent on input devices.
When following this instruction, you do not need to connect any input devices for setting up your Raspberry Pi. You just need a wifi connection as you will set up everything over ssh. All kinds of projects can be done with this setup as most of them do not require any external input devices or HDMI monitors.
Let’s get started!
Download Raspbian Lite Image:
https://www.raspberrypi.org/downloads/raspbian/
Find your SD-card with:diskutil list
Unmount SD-card with:diskutil unmountDisk /dev/diskX
(X is the number of your SD-card you found out in the step before)
Copy the image to your SD-card with:sudo dd bs=1m if=theImagePath.img of=/dev/rdiskX conv=sync
Please make absolutely sure, that the number (“X”) belongs to your SD-card!
To connect to your wifi network, add file called wpa_supplicant.conf
to partition “boot” (e.g. via finder), with the following content:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=DE
network={
ssid="YOUR WIFI'S SSID"
psk="YOUR WIFI PASSWORD"
}
Code language: JavaScript (javascript)
Add an empty file called ssh
without any content to the same partition to enable ssh.
Navigate via terminal to the boot partition on your SD-card:
cd /Volumes/boot
Add an empty file called ssh
:
touch ssh
Insert SD and boot up your RPi
Insert the SD-card into your Raspberry pi, connect a power source and wait for it to connect to your wifi. This takes about 30 seconds. You should see your raspberry pi in your wifi routers web interface. Its hostname should be raspberrypi
If your Raspberry pi is connected, you should be able to establish an ssh connection. The defautl username is pi
, the default hostname is raspberrypi
(alternatively you can use its IP adress if your router does not resolve its hostname) and the default password is raspberrypi
as well. Go to a terminal and type:
pi@raspberrypi
You are asked for a password, the default one is: raspberrypi
.
Troubleshoot ssh connection failure
If you cannot connect to the raspberry because of some ssh warning like this:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for raspberrypi has changed,
and the key for the corresponding IP address xxxxxxx
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:xxxxxxx
Please contact your system administrator.
Add correct host key in /Users/user/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/user/.ssh/known_hosts:37
ECDSA host key for raspberrypi has changed and you have requested strict checking.
Host key verification failed.
Code language: CSS (css)
You probably had another Raspberry pi connected via ssh before. Just follow the hint in the error message and edit the file known_hosts
.
You can edit it very easy via the text editor nano
from within the terminal:
nano ~/.ssh/known_hosts
Search for the line saying raspberrypi
, press CTRL+K (to cut the line), then CTRL+X to quit, press Y accept your changes and finally press ENTER to save. You can make a backup of your existing known_hosts
file if you save the changed file under another name before overwriting it.
If everything worked fine you should now be able to connect via ssh to your raspberry.
You should see pi@raspberrypi:~ $
in your terminal, saying that you are logged in as the user pi
on your Raspberry Pi.
Disable Wifi Powersaving
At first you should deactivate the wifi power saving of the raspberry. Otherwise the Raspberry would power down the wifi module after some time of inactivity making the Raspberry inaccessible. You deactivate it with:
sudo iw wlan0 set power_save off
In addition to that you have to make sure that the power saving is deactivated whenever the Raspberry is rebooted. For that you have to edit another configuration file:
sudo nano /etc/network/interfaces
Add at the end of the file the following code:
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off
Now you are ready to go! Install a webserver, mailserver, connect sensors, etc. 🚂
Sources:
https://www.heise.de/select/ct/2017/22/1508780300482172
https://www.raspberrypi.org/documentation/installation/installing-images/mac.md