Raspberry Pi Notes

Page Contents

Install OS

See: Raspberry Pi OS / Raspberry Pi Imager.

Download the imager setup file for your OS and install the tool. With the tool all you need to do is choose the type of OS you want to install, select the Micro SD card to install to and click the "Write" button.

Get Software/Hardware Versions

See also: RPi Hardware History.

Debian version: cat /etc/debian_version
OS release: cat /etc/os-release
Kernel version: uname -a
Hardware: cat /proc/cpuinfo

Setup Headless Wifi Mode

See: SSH (Secure Shell), RaspPi documentation.

In headless mode you don't need to attach a monitor or keyboard/mouse to your Pi. Just SSH into it [Ref]!

  1. Use Raspberry Pi Imager to flash a micro SD card with Raspberry Pi OS
  2. Create emtpy file in flash root called ssh. RPi OS sees this and enables SSH with password logins.
  3. Create file wpa_supplicant.conf in flash root (boot (D:)). Add the following contents, making sure that you use Linux-style newlines, "\n", if editing on Windows, which uses CRLF, or, "\n\r":
    country=GB
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
    scan_ssid=1
    ssid="your_wifi_ssid"
    psk="your_wifi_password"
    }
  4. SSH into raspberrypi.local using username pi and passwrod raspberry.

Upon first boot the ssh and wpa_supplicant.conf files will be deleted. Once the RPi boots, everything should be persistent and the network and ssh available on subsequent boots.

Setup VNC

See: VNC (Virtual Network Computing), RaspPi documentation.

Install Docker

Since Raspbian Jesse installing Docker is as easy as [Ref]:

curl -fsSL https://get.docker.com  | sudo sh  # Get official Docker install script and run it
sudo groupadd docker                          # Create the docker group
su -s ${USER}                                 # Log out and log back in so that group membership is re-evaluated
sudo usermod -aG docker ${USER}               # Add non-root user to docker group. Default user is "pi" on RPi OS.
sudo shutdown -r now                          # For some reason YOU HAVE TO REBOOT!

Later, to upgrade Docker, don't re-run the script, just do:

sudo apt-get upgrade

If you ever need to uninstall your Docker install do:

sudo apt-get purge docker-ce docker-ce-cli
sudo rm -rf /var/lib/docker

Setup I2C & SPI

Run sudo raspi-config and select Interfacing Options > I2C | SPI. Select enable, save and exit.

To automate the use of raspi-config in scripts does not appear to be the default way of using the util, but if can be done [Ref] [Ref]:

			raspi-config nonint do_i2c 0 # Enable I2C
			raspi-config nonint do_spi 0 # Enable SPI
		

Security

Encrypt Your Home Folder & Disable Swap

See How to Encrypt Raspberry Pi home folder, by Syed Balal Rumy (April 26, 2018).

  1. Type sudo nano /etc/lightdm/lightdm.conf. Comment out line reading autologin-user=pi. Ctrl+X, then Y, and then <Return> to save and exit.
  2. Install: sudo apt-get install ecryptfs-utils lsof cryptsetup.
  3. Reboot and log back in using default user pi.
  4. Add new user: sudo adduser NEW-USER-NAME.
  5. Encrypt new user home: sudo ecryptfs-migrate-home -u NEW-USER-NAME.
  6. Give new user sudo: sudo visudo. Copy line reading root ALL=(ALL:ALL) ALL as NEW-USER-NAME ALL=(ALL:ALL) ALL. Ctrl+X, then Y, and then <Return> to save and exit.
  7. Login as new user and migrate data. Disable swap: sudo swapoff -a -v.
  8. Secure delete data in pi home folder using shred -zu FILENAME.
  9. Fix permissions and user/group errors if need be: sudo chmod 0750 ..., chown NEW-USER-NAME ..., chgrp NEW-USER-NAME ... and so on.
  10. Set the root user password: sudo passwd root.
  11. Reboot Pi and login with default. Type su and enter root passwrd set in previous set.
  12. Type cd /home/NEW-USER-NAME && ls. You should only be able to see Access-Your-Private-Data.desktop and README.txt. You should not be able to see any of the new user's real files!

It is also advisable to disable the on-disk swap file usage as these will no be encrypted by ecryptfs:

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo systemctl disable dphys-swapfile
sudo shutdown -r now

Disable The Default Pi User

sudo passwd --lock pi
sudo usermod --expiredate 1 pi

Malware

Try the Linux Malware Detect (LMD or maldet).

Mount Remote Windows Directory

If you want to use your local machine for development and the Pi to simply run the code you can use the following instructions.

  1. On your Windows machine, share your local development directory.
  2. On the Pi, execute the following. You will be asked for a password. This will be your Windows login password.
    sudo mkdir /mnt/a-mount-dir-name
    sudo mount -t cifs -o username=<Windows user name>,uid=$(id -u),gid=$(id -g),forceuid,forcegid //<PC's IP address>/<Windows folder share name> /mnt/a-mount-dir-name