Setup up a new Raspberry PI headless (without using a monitor, keyboard, mouse, LAN-cable) using WIFI and SSH.
Some assumptions:
- on a mac (local machine)
- the SD card is
disk2
at/dev/disk2
- the PI image is named
image.img
- the PI's IP is
10.0.0.1
- there is some ssh-key at
~/.ssh/id_rsa
(on the mac) - there is a wifi
Download a current Lite image of Raspbian from https://www.raspberrypi.org/downloads/raspbian/.
wget -O image.img https://downloads.raspberrypi.org/raspbian_lite_latest
# or
curl https://downloads.raspberrypi.org/raspbian_lite_latest --output image.img
https://www.raspberrypi.org/documentation/installation/installing-images/mac.md
# find the SD card (e.g. /dev/disk2 or mayby /dev/disk4)
diskutil list
# unmount the entire card (not just the partition)
diskutil unmountDisk /dev/disk2
# will most likely fail (dd: invalid number '1m') due to installed GNU coreutils
sudo dd bs=1m if=image.img of=/dev/rdisk2 conv=sync
# so run:
sudo dd bs=1M if=image.img of=/dev/rdisk2 conv=sync
# after the dd one could theoretically eject the card running
sudo diskutil eject /dev/rdisk2
Enable SSH:
(By creating an empty filename named ssh
in the boot root directory.)
touch /Volumes/boot/ssh
Enable WIFI (and add the SSID and password)
touch /Volumes/boot/wpa_supplicant.conf
It's contents:
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="🌊"
psk="the-password"
}
Now eject the SD card: sudo diskutil eject /dev/rdisk2
.
And put the card into the PI and power the PI.
Now you should find the PI in your network (check router, scan your network or use the Fing App in your phone). Obtain the IP address.
Maybe assign a static IP in your router.
Add SSH public key:
ssh-copy-id -i ~/.ssh/id_rsa pi@10.0.0.1
# or copy the key and create in on the pi
cat ~/.ssh/id_rsa.pub | pbcopy
# and on the pi:
mkdir ~/.ssh
vi ~/.ssh/authorized_keys
Optionally: Add ssh shortcut to ~/.ssh/config
:
Host pi
HostName 10.0.0.1
User pi
Raspi Config
sudo raspi-config
Updates!
sudo apt-get update -y
sudo apt-get upgrade -y
Static IP
sudo vi /etc/dhcpcd.conf
- change pi password (
passwd
) or add own sudo user (sudo adduser USER sudo
) and remove pi user (sudo deluser -remove-home pi
). - if public keys are set up, disable password auth.
- iptables
- further security options (e.g. change SSH port)
- install fish shell
- add dotfiles for shell, tmux and vim
Change/Update the WIFI settings:
sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
Change sudo password
sudo passwd root
Cleanup packages
sudo apt autoremove --purge && sudo apt clean