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]!
- Use Raspberry Pi Imager to flash a micro SD card with Raspberry Pi OS
- Create emtpy file in flash root called
ssh
. RPi OS sees this and enables SSH with password logins. - 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" }
- SSH into
raspberrypi.local
using usernamepi
and passwrodraspberry
.
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).
-
Type
sudo nano /etc/lightdm/lightdm.conf
. Comment out line readingautologin-user=pi
. Ctrl+X, then Y, and then <Return> to save and exit. -
Install:
sudo apt-get install ecryptfs-utils lsof cryptsetup
. -
Reboot and log back in using default user
pi
. -
Add new user:
sudo adduser NEW-USER-NAME
. -
Encrypt new user home:
sudo ecryptfs-migrate-home -u NEW-USER-NAME
. -
Give new user sudo:
sudo visudo
. Copy line readingroot ALL=(ALL:ALL) ALL
asNEW-USER-NAME ALL=(ALL:ALL) ALL
. Ctrl+X, then Y, and then <Return> to save and exit. -
Login as new user and migrate data. Disable swap:
sudo swapoff -a -v
. -
Secure delete data in
pi
home folder usingshred -zu FILENAME
. -
Fix permissions and user/group errors if need be:
sudo chmod 0750 ...
,chown NEW-USER-NAME ...
,chgrp NEW-USER-NAME ...
and so on. -
Set the root user password:
sudo passwd root
. -
Reboot Pi and login with default. Type
su
and enter root passwrd set in previous set. -
Type
cd /home/NEW-USER-NAME && ls
. You should only be able to seeAccess-Your-Private-Data.desktop
andREADME.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.
- On your Windows machine, share your local development directory.
-
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