Minimal Raspberry Pi headless setup

Requirements

The setup

Getting the operating system

Torrent the Raspberry Pi OS iso or download it directly. I recommend torrenting. I also recommend getting the Lite version since it has the least bloat.

https://www.raspberrypi.org/software/operating-systems/

If you chose the direct download instead of the torrent, you need to verify its hash:

sha256sum rpi.iso

Flashing

Flash the iso on the sdcard.

sudo dd if=/path/to/rpi.iso of=/dev/sdX status="progress" && sync

Where rpi.iso is the iso you just downloaded and X is the letter of the sdcard as seen from

lsblk --fs

It's probably the one with FAT32, vfat or something similar for a filesystem.

Configuring

Now mount the smaller partition of the sdcard you just flashed.

sudo mount /dev/sdX1 /mnt

Append ip=10.3.14.1 to cmdline.txt.

sudo sed -i "s/$/ ip=10.3.14.1/" /mnt/cmdline.txt

Create an ssh file.

sudo touch /mnt/ssh

Unmount the partition.

sudo umount /mnt

Put the sdcard in the Raspberry Pi and boot it.

Connecting

Connect your computer to the Raspberry Pi with an Ethernet cable and determine the name of your Ethernet interface. It should be the first thing in blue from the command bellow. It's usually something like eth0 or enp0s25.

ip -c link show

Give your interface an IP address. It can be anything, it really doesn't matter.

sudo ip addr add 10.3.14.5/24 dev eth0

Then set the interface as the gateway to the 10.3.14.0/24 network. That's just fancy language for saying: if you want to talk to a device within the network (the pi), use the Ethernet cable.

sudo ip route add 10.3.14.0/24 dev eth0

Now you can ssh into the Raspberry Pi. The default password is "raspberry"

ssh pi@10.3.14.1

After you are done with the ssh session, remove the routing table record, get rid of the IP address and bring the interface down.

sudo ip route delete 10.3.14.0/24 dev eth0
sudo ip addr flush eth0
sudo ip link set eth0 down

I also have a record in ~/.ssh/config purely for convenience.

# EEEthernet pi
host epi
    HostName 10.3.14.1
    User pi
    port 22

That's it! There's no need for bloated network managers or their confusing configurations. There's no need for a monitor, keyboard, mouse, vnc, wifi, or anything else. You can just use the networking capability that's built into Linux.

Notes

I consider the Raspberry Pi compromised since it has a "secure execution" environment so I don't recommend putting things on it you wouldn't willingly give to the alphabet agencies. Some people like to use it as a mailserver. But just because you "own" the hardware does not make it secure. I myself simply host (or will host) my email on a vps but I don't consider it anything less than public, at least when it's not encrypted with gpg or something.

See Also

Recover password on a headless raspberry pi (webpage contains bloat)