How to setup a headless Raspberry Pi

Summary of steps

  • Write a disk image to the SD card
  • Add wifi credentials and enable ssh
  • Change the Pi’s hostname and add ssh key(s)
  • Reboot
  • Verify passwordless authentication works
  • Disable password authentication

Write a disk image to the SD card.

Setup wifi and enable ssh

$ cd /Volumes/boot # this path may vary
$ touch ssh
$ vi wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

Hostnames and usernames

$ ssh pi@raspberrypi.local
$ # or ssh ubuntu@ubuntu.local

Change the hostname and add ssh keys

$ sudo vi /etc/hostname
$ sudo vi /etc/hosts
$ cd ~
$ mkdir .ssh
$ chmod 700 .ssh
$ # make sure to run this on the local machine, not the pi
$ scp ~/.ssh/ pi@raspberrypi.local:.ssh/authorized_keys
$ # alternatively, on the pi:
$ vi .ssh/authorized_keys # and paste the public key


$ sudo reboot now

Login again

$ ssh pi@newhostname.local

Disable password authentication

$ sudo vi /etc/ssh/sshd_config
PasswordAuthentication no
sudo systemctl restart sshd.service

Ready to go

$ sudo apt update && sudo apt upgrade




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Its Time For a Hybrid Telegram & Signal Messenger

HackTheBox: Lame

Hping3 to Meet You on the Other Side of the Firewall

Security 1: Encryption/ Decryption vs Hashing

COM Objects P.1: The Hidden Backdoor in Your System

How and where to report a scam, hack or malicious activity involving digital assets

{UPDATE} Penguin Fly Free Hack Free Resources Generator

Web Protocols Explained As If You Were Asleep Since THE 90s

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Bostock

Alex Bostock

More from Medium

How to setup a media server on your Raspberry PI

Create a cloud using NextCloud, Raspberry Pi, and a USB HDD from scratch

Free Command in Linux/Unix

Stop paying for your SSL certificates