Skip to content

Initial Raspberry Pi Setup

Tristan Keen edited this page Feb 6, 2021 · 4 revisions

If you want to access & configure the Raspberry Pi via SSH rather than connecting a monitor & keyboard (i.e. "headless"), you can enable the SSH Server & copy in your WiFi SSID and password so it connects to your network automatically.

  1. Create a SD card with your boot image, e.g. using the Imager. I suggest the choosing Raspbian Pi OS Lite if you don't need a desktop.
  2. Copy the two non-readme files, ssh and wpa_supplicant.conf from the setup/headless folder to the "boot" partition of the SD card you can see from Windows. Yes the ssh file is meant to be empty & don't add any file extensions to either.
  3. Edit the wpa_supplicant.conf file now on the SD card to fill in your WiFi SSID and password or encrypted PSK. Use a non-formatting, non-renaming editor like Notepad++ or VSCode.
  4. Eject the SD card, plug it into the RPi and let it boot - it can take 5 mins for the initial boot to proceed enough for ssh pi@raspberrypi to work, with the standard default password of raspberry.

Switching to SSH key based authentication


NOTE

If you don't yet have a SSH key, see the GitHub guide.


I strongly recommend switching from passwords to authentication via your local SSH key, usually stored on your laptop at ~/.ssh/id_rsa (private key) and ~/.ssh/id_rsa.pub (public key):

# Copy your SSH public key from laptop to RPi for future authentication
# (you'll need to type in the RPi's, probably default, password)
ssh-copy-id pi@raspberrypi

# Check it works
ssh pi@raspberrypi

# <on the RPi> Update the standard password, disable password authentication, and rename the host
passwd
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config

# Finally, rename the RPi from the generic "raspberrypi" to something specific (change `newhostname`!) and reboot it
sudo raspi-config nonint do_hostname newhostname
sudo reboot

# Wait a minute and then try reconnecting, this time no need to type a password!
ssh pi@newhostname

Clone this wiki locally