Skip to content

Instantly share code, notes, and snippets.

@berikv
Created July 25, 2019 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berikv/4b90081c7f59bc544301e896f97cec58 to your computer and use it in GitHub Desktop.
Save berikv/4b90081c7f59bc544301e896f97cec58 to your computer and use it in GitHub Desktop.
Raspberry pi ssh headless setup

Tested on the Raspberry Pi 4.

1 Download

Download Rasbian at https://www.raspberrypi.org/downloads/raspbian/

Open the raspbian*.img file. This mounts the image as "boot" volume.

2 Configure the image

Open Terminal.app

This will enable ssh:

cd /Volumes/boot
touch ssh

This will setup wireless networking. Replace and with your network:

cat << EOF > wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<NL>

network={
	scan_ssid=1
	ssid="<Wifi network>"
	psk="<Wifi password>"
}

EOF

Optionally you can configure a static IP in wpa_supplicant.conf. Just make sure that the IP you select is in your network and is currently not in use.

3 Burn the image to an SD

  • Close the terminal
  • Eject the "boot" volume (using Finder or DiskUtility).
  • Insert the SD card (use a camera or any other SD card reader)
  • Reopen the terminal
  • Run diskutil list and find the /dev/diskN for your SD card
  • Eject the SD card (using Finder or DiskUtility), Do Not remove the SD card from your computer
  • Run sudo dd if=</path/to/raspbian.img> of=</dev/diskN> bs=1m conv=sync; say done
  • Wait until the process completes (this can take an hour or more, depending on the size of the image)

4 Boot the pi

  • Install the SD card in the raspberry pi
  • Power on the raspberry
  • Give the pi a couple of minutes to boot the first time
  • The raspberry will connect to the Wifi once booted

5 Connect to the pi

  • Find the ip of your rasbperry on your router
  • Run ssh pi@<ip address of your pi>
  • Type "yes" for adding to the list of known hosts
  • Type the password "raspberry"

6 Update the pi

While connected via ssh to the raspberry:

  • Run sudo apt-get update
  • Run sudo apt-get dist-upgrade
  • Run sudo reboot

7 Setup a custom user account

  • Run ssh pi@<ip address of your pi>
  • Run sudo add user <your username>
  • Run sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi <your username>
  • logout of ssh (Ctrl-D)
  • Reconnet using the new user ssh <yourusername>@<ip.address.of.raspberry>
  • Run sudo vi /etc/polkit-1/localauthority.conf.d/60-desktop-policy.conf
  • Replace unix-user:pi with your username
  • Run sudo vi /etc/lightdm/lightdm.conf
  • Replace autologin-user=pi with your username
  • Run sudo userdel pi

8 Setup authorized connect

  • Disconnect from the raspberry (Ctrl-D)
  • Run [ -f ~/.ssh/id_rsa.pub ] || ssh-keygen -t dsa -f ~/.ssh/id_rsa.pub
  • Run cat ~/.ssh/id_rsa.pub | ssh <yourusername>@<ip.address.of.raspberry> "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
  • Now you should be able to log in without a password: ssh <yourusername>@<ip.address.of.raspberry>

9 Other setup

  • Run apt install vim zsh git
  • Set zsh as the default shell chsh -s /bin/zsh
  • Install Oh my zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

10 Install plex media server

  • Download plex wget https://downloads.plex.tv/plex-media-server-new/1.15.3.876-ad6e39743/debian/plexmediaserver_1.15.3.876-ad6e39743_armhf.deb

  • Install sudo dpkg -i plexmediaserver_1.15.3.876-ad6e39743_armhf.deb

  • Setup update source echo deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list

  • Setup source signing key curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -

  • Update sources sudo apt update && sudo apt upgrade

  • Open plex on http://:32400/web/

11 Mount usb drives

  • For Mac compatibility sudo apt install hfsplus hfsutils hfsprogs
  • Create mountpoints sudo mkdir /mnt/Disk1 /mnt/Disk2
  • Add your drive to /etc/fstab:
UUID=<drive uuid> /mnt/Disk1 ext4 defaults,nofail,errors=remount-ro 0 2
UUID=<drive uuid> /mnt/Disk2 hfsplus defaults,nofail 0 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment