-
Download Raspbian image: https://www.raspberrypi.org/downloads/raspbian/.
-
Unzip it (optional).
-
Format SD card with SD Memory Card Formatter application (https://www.sdcard.org/downloads/formatter/).
-
Open Etcher application (https://www.balena.io/etcher/)
-
Select from hard drive the Raspbian .img or .zip file.
-
Select the SD card.
-
Click [Flash].
-
Place a file named
ssh
, without any extension, onto the boot partition of the SD card:$ cd /Volumes/boot $ touch ssh
-
Eject card.
-
Create a file named
wpa_supplicant.conf
in the boot partition:$ cd /Volumes/boot $ nano
-
Write the configuration for the wireless network(s):
(file)
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid=“ssid-name1” scan_ssid=0 psk=encrypted-password priority = 2 } network={ ssid=“ssid-name2” scan_ssid=0 psk=encrypted-password priority = 1 }
(end of file)
-
Save and exit:
[Ctrl + O]
[Ctrl + X] -
Eject card.
-
Change “raspberrypi” to the new hostname, save and exit:
$ sudo nano /etc/hostname
-
Find line starting with 127.0.0.1 and change “raspberrypi” to the new hostname, save and exit:
$ sudo nano /etc/hosts
-
Reboot
$ sudo reboot
-
Change password:
$ passwd
Some info: https://medium.com/risan/upgrade-your-ssh-key-to-ed25519-c6e8d60d3c54
SSH supports several public key algorithms for authentication keys.
The algorithm is selected using the -t
option and key size using the -b
option.
-
dsa - bad!
-
rsa - ok
Key sizes: 768 (min), 4096 (recommended), 16384 (max) -
ecdsa - good
Key sizes: 256, 384, 521 -
ed25519 - best
Key size: 256 (fixed)
To check all available SSH keys on the computer run:
for key in ~/.ssh/id_*; do ssh-keygen -l -f "${key}"; done | uniq
METHOD 1
-
On local machine
Use existing key in~/.ssh
or generate a new one withssh-keygen
:$ cd ~/.ssh $ ssh-keygen -t ed25519
-
On local machine
Install the SSH key on the Raspberry Pi as an authorized key withssh-copy-id
:$ ssh-copy-id -i ~/.ssh/<key> <user>@<host>
METHOD 2
-
On local machine
Use existing key in~/.ssh
or generate a new one withssh-keygen
:$ cd ~/.ssh $ ssh-keygen -t ed25519
-
On remote machine
Create the.ssh
directory and theauthorized_keys
file with the correct permissions:$ mkdir .ssh $ touch ~/.ssh/authorized_keys $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/authorized_keys
-
On local machine
Copy SSH public key to Raspberry Pi:$ scp ~/.ssh/id_ed25519.pub pi@rpi:~/.ssh/
-
On remote machine
Add SSH public key toauthorized_keys
file:$ cd ~/.ssh $ cat id_ed25519.pub >> authorized_keys $ rm id_ed25519.pub
-
Replace default prompt in
~/.bashrc
file with:# Custom prompt PS1='${debian_chroot:+($debian_chroot)}\[\033[01m\]\u@\h\[\033[01m\]:\[\033[01m\]\w \[\033[00;35m\]❯\[\033[00m\] '
-
Add the following lines to file
~/.inputrc
:# Incremental history searching "\e[A": history-search-backward "\e[B": history-search-forward "\e[C": forward-char "\e[D": backward-char # TAB completion set completion-ignore-case on set show-all-if-ambiguous on set show-all-if-unmodified on
-
Edit static text:
$ sudo nano /etc/motd
-
Edit dynamic content:
$ cd /etc/update-motd.d
-
Create/edit file:
$ sudo nano /etc/update-motd.d/10-uname
(file)
#!/bin/sh uname -snrvm echo "\033[00;32m●\033[00m Connected to `iwgetid`\033[00m"
(end of file)
-
Download and install:
$ sudo apt-get install tmux
-
To create user:
$ sudo adduser user
-
To add new user to sudoers:
Some info: https://www.garron.me/en/linux/visudo-command-sudoers-file-sudo-default-editor.html$ sudo visudo
Edit the file as below:
# User privilege specification root ALL=(ALL:ALL) ALL user ALL = NOPASSWD: ALL
Save and exit.
-
To delete user:
$ sudo userdel -r user
-
Encrypt WiFi password:
$ wpa_passphrase {ssid} {password}
-
Edit configuration:
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
(file)
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid=“ssid-name1” scan_ssid=0 psk=encrypted-password priority = 2 } network={ ssid=“ssid-name2” scan_ssid=0 psk=encrypted-password priority = 1 }
(end of file)
-
Check network being used:
$ iwgetid
-
List of available networks:
$ wpa_cli > scan > scan_results
-
Info about wireless network interface (wlan0/1):
$ iwconfig wlan0 $ sudo iwlist wlan0 scan | egrep "Cell|ESSID|Signal|Rates"
-
Disable power management for WiFi:
$ sudo iwconfig wlan0 power off
Add this to the
/etc/rc.local
file so it runs when RPI restarts. -
Disable WiFi
$ sudo ifconfig wlan0 down
To keep WiFi off across boots, add this line to
/boot/config.txt
:dtoverlay=disable-wifi
-
Plug USB disk in.
-
List available block storage devices with UUIDs and free disk space:
$ lsblk $ lsblk -f $ df -h
External drives will have the name sdx, where x=a,b,c,...
Some info: https://www.linuxnix.com/lsblk-command-explained-with-examples/ -
Create partitions:
$ sudo fdisk /dev/sda Command (m for help): o (wipe existing partitions) Command (m for help): n (add new partition) Select (default p): [ENTER] Partition number (1-4, default 1): [ENTER] First sector (2048-613355519, default 2048): [ENTER] Last sector, +sectors or +size{K,M,G,T,P} (2048-613355519, default 613355519): [ENTER] Command (m for help): w (write changes)
-
Check the new partition was created:
$ sudo fdisk -l $ sudo fdisk -l /dev/sda
-
Format partition and attach a label:
$ sudo mkfs.ext4 -L U1 /dev/sda1 /dev/sda1 contains a ext4 file system - Proceed anyway? (y,n): y
-
Create mount point:
$ sudo mkdir /mnt/u1
-
Mount:
$ sudo mount /dev/sda1 /mnt/u1
-or-
$ sudo mount -L U1 /mnt/u1
-
Test mount point:
$ ls /mnt/u1/
-
Configuration for mounting drive at system boot:
$ sudo nano /etc/fstab
Add line after last partition of the list:
LABEL=U1 /mnt/u1 ext4 defaults,auto,noatime,rw,users 0 0
(UUID can be used instead of LABEL, run
blkid
to list the partitions and their UUIDs)Save and exit:
[Ctrl+O]
[Ctrl+X] -
Reboot:
$ sudo reboot
-
Change and verify permissions:
$ sudo chown pi:pi /mnt/u1 $ sudo chmod 755 /mnt/u1 $ ls -l /mnt/ drwxr-xr-x 3 pi pi 4096 Nov 4 21:27 u1
-
Check filesystem for errors:
$ sudo umount /mnt/u1 $ sudo fsck -Mn /dev/sda1
Some info: https://docs.remote.it/platforms/quick-start-on-raspberry-pi/install-remote.it
-
Install the remote.it
connectd
package:$ sudo apt install connectd
-
Run the interactive installer:
$ sudo connectd_installer
Some info: https://help.realvnc.com/hc/en-us/articles/360002249917-VNC-Connect-and-Raspberry-Pi
-
Install RealVNC:
(pre-installed on Raspbian)$ sudo apt-get update $ sudo apt-get install realvnc-vnc-server
-
Start virtual desktop:
$ vncserver :<display-number> -geometry 1600x1200 -randr 1600x1200,1440x900,1024x768
-
Resize with:
$ xrandr -s 1600x1200 $ xrandr -s 1440x900 $ xrandr -s 1024x768
-
Convenient to put all of these options in
~/.vnc/config
file:-randr 800x600,1024x768,1280x800,1280x960,1280x1024,1680x1050,1920x1080,3360x1050,1024x700,1200x740,1600x1000,3200x1000
-
Stop virtual desktop:
$ vncserver -kill :<display-number>
-
To start VNC Server now:
$ sudo systemctl start vncserver-x11-serviced.service
-
To start VNC Server at next boot, and every subsequent boot:
$ sudo systemctl enable vncserver-x11-serviced.service
-
To stop VNC Server:
$ sudo systemctl stop vncserver-x11-serviced.service
-
To prevent VNC Server starting at boot:
$ sudo systemctl disable vncserver-x11-serviced.service
-
Execute commands:
$ sudo nano /etc/rc.local
Add the commands or scripts before the
exit 0
so it runs when RPI restarts. Some info : https://www.raspberrypi.org/documentation/linux/usage/rc-local.md -
Change configuration parameters:
$ sudo nano /boot/config.txt
Add the changes as needed. Example:
dtoverlay=disable-wifi
Some info: https://www.raspberrypi.org/documentation/configuration/config-txt/See
/boot/overlays/README
for more info:
https://github.com/raspberrypi/firmware/tree/master/boot/overlays -
Run scripts:
$ crontab -e
Use
@reboot
at the begining of the line and&
at the end.
Example:@reboot python /home/pi/example.sh &
[Ctrl + O]
[Enter]
[Ctrl + X]Crontab man page: https://manpages.debian.org/buster/cron/crontab.5.en.html
Crontab tool: https://crontab.guru
-
Edit the two configuration files:
/etc/ssh/ssh_config
/etc/ssh/sshd_config
-
Add the following line to the bottom of each configuration file:
# RaspberryPi Zero W Onboard WiFi Fix IPQoS 0x00 #IPQoS cs0 cs0
-
Restart
ssh
andsshd
:$ sudo systemctl restart ssh $ sudo systemctl restart sshd
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=138631&start=125
IPQoS 0x00
https://forum.core-electronics.com.au/t/pi-zero-w-problem/944/4
#RaspberryPi 3 Onboard WiFi Fix
IPQoS cs0 cs0
https://community.openenergymonitor.org/t/ssh-issues-specific-to-pi3-onboard-wifi/2730