A collection of useful tips and tricks, implemented step by step but without explanation
Samba Setup
- Run
sudo apt-get install samba samba-common-bin
- Run
mkdir -m 1700 share
- Run
sudo nano /etc/samba/smb.conf
Add the following at the end of the file:
[share]
Comment = Shared folder on RPi
Path = home/pi/share
Browseable = yes
Writeable = Yes
create mask = 0700
directory mask = 0700
; This line and the following may be omitted but are here
; commented out to keep them available for future use if needed
; Public = yes
; Guest ok = yes
; only guest = no
- Run
sudo smbpasswd -a pi
and enter the password you’ll use to access the share remotely - Run
sudo /etc/init.d/smbd restart
Basic SSH/SCP
To access the Pi on the network: ssh pi@.local
To transfer a file to the Pi: scp pi@.local:/
Advanced SSH
- On client:
cd $HOME
mkdir .ssh
chmod 700 .ssh
cd .ssh
ssh-keygen -t rsa -f
scp .pub @:/home//.ssh/.pub
nano config
- Add the following on separate lines, no numbers, one space inset after first line:
Host
Hostname
User
IdentityFile ~/.ssh/
StrictHostChecking yes
- On server:
cd $HOME
mkdir .ssh
chmod 700 .ssh
cd .ssh
cat .pub >> authorized_keys
sudo nano /etc/ssh/sshd_config
- Change
#Password Authentication yes
toPasswordAuthentication no
- On client:
ssh
Note For iPad access (using Termius) generate the keys on the server, copy private key to iPad, set up Termius for key access, delete private key on server.
Change Default Shell
chsh -s $(which zsh)
Mount a USB Disk at the Command Line
- Connect disk then run:
sudo fdisk -l
gives, for example,/dev/sda1
as the disk file reference - Run
sudo mkdir /media/usbdrive
- Run
sudo chgrp -R users /media/usbdrive
- Run
sudo chmod -R g+w /media/usbdrive
- Run
sudo mount /dev/sda1 /media/usbdrive -o rw -t vfat
Note Steps 2-4 can be omitted if /media/usbdrive
already exists
Mount a NAS Drive at the Command Line
- Run
mkdir /home/pi/nas
- Run
sudo mount -t cifs -o user=<your_nas_username>,password=<your_nas_password> //192.168.0.2/ /home/pi/nas
- Optional: mount drive at startup
- Run
sudo nano /etc/fstab
- Add as a line at the end:
//192.168.0.2/ /home/pi/nas cifs user=<your_nas_username>,password=<your_nas_password>,noauto,x-systemd.automount 0 0
- Run
Version Info
- For Linux version, run:
cat /proc/version
- For the Pi’s board version, run:
cat /proc/cpuinfo
Disable internal Bluetooth
- Run
sudo nano /boot/config.txt
- Add to the end of the file:
dtoverlay=pi3-disable-bt
- Run
sudo systemctl disable hciuart.service
- Run
sudo systemctl disable bluealsa.service
- Run
sudo systemctl disable bluetooth.service
- Run
sudo shutdown -r now
Set up WiFi at the Command Line
- Run sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
- At the end of the file add:
network={
ssid=""
psk=""
key_mgmt=WPA-PSK
}
Note Do not put spaces either side of the equals sign. - To perform a scan to check WiFi operation, run
sudo iwlist wlan0 scan
You can add multiple networks.
Use Dropbox
- Run
git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
- Run
cd Dropbox-Uploader
- Run
chmod +x dropbox_uploader.sh
- Go to https://developer.dropbox.com and sign in. Create an app then generate an app token. Paste this into
dropbox_uploader.sh
when requested (on first run). - To upload an item, run
./dropbox_uploader.sh upload
To delete an item, run./dropbox_uploader.sh delete
Script source: https://github.com/andreafabrizi/Dropbox-Uploader
Node.js Setup
For Pi 3 B+
- Run
curl -sL https://deb.nodesource.com/setup_{version_number}.x | sudo -E bash -
- Run
sudo apt install -y nodejs
Further information: https://github.com/nodesource/distributions
For Pi Zero
Visit https://nodejs.org/dist/latest to find out which is the latest version (X.Y.Z), eg. https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-armv6l.tar.gz
mdkir tmp
cd tmp
wget https://nodejs.org/dist/vX.Y.Z/node-vX.Y.Z-linux-armv6l.tar.gz
tar -xzf node-vX.Y.Z-linux-armv6l.tar.gz
cd node-vX.Y.Z-linux-armv6l
sudo cp -r * /usr/local/
export PATH=$PATH:/usr/local/bin
cd ~
rm -r tmp
Back-up SD Card to Mac
Obtain the disk number of the SD card:
diskutil list
diskutil umountdisk /dev/disk1
Copy the SD contents to a file, piping via gzip to reduce the size:
sudo dd if=/dev/rdisk1 bs=1m | gzip > ~/Desktop/pi.gz
To restore, get the disk number using diskutil as above, then unmount the card:
diskutil umountdisk /dev/disk1
Restore from a local file, pi.gz:
RPi.GPIO Basics
To import the RPi.GPIO module:
import RPi.GPIO as GPIO
Specify which pin numbering system you are using — Raspberry Pi standard (GPIO.BOARD
) or Broadcom specification (GPIO.BCM
) — you are using using:
GPIO.setmode(GPIO.BOARD)
To silence multiple usage warnings:
GPIO.setwarnings(False)
Configure a pin (‘channel’ in RPi.GPIO parlance):
GPIO.setup(pin_number, GPIO.IN)
GPIO.setup(pin_number, GPIO.OUT)
To specify an initial value for an output pin:
GPIO.setup(pin_number, GPIO.OUT, initial=GPIO.HIGH)
Note Instead of one pin number, pass in an array of pin numbers.
To read the value of a GPIO pin:
pin_value = GPIO.input(pin_number)
To set the output state of a pin:
GPIO.output(pin_number, state)
where state can be 0
/ GPIO.LOW
/ False
, 1
/ GPIO.HIGH
/ True
, or a tuple of values when passing in an array of pin numbers.
To clean up any resources used:
GPIO.cleanup()
Specify a pin number (of array of pin numbers) for finer cleanup control.
VNC Virtual Desktop
To run a virtual desktop ad hoc from the command line:
vncserver
Options
To set the virtual desktop size:
-randr=<X>x<Y>
where X
and Y
are the screen width and height.
To stop the virtual desktop:
-kill :<n>
where n
is the desktop number (default: 1)
Start the Virtual Desktop at Boot
sudo nano /etc/systemd/system/vncvirtualdesktop.service
- Add the script below.
sudo systemctl enable vncvirtualdesktop.service
[Unit]
Description=Start VNC Server Virtual Desktop
[Service]
Type=oneshot
ExecStart=/bin/su pi -c /usr/bin/vncserver
ExecStop=/usr/bin/vncserver -kill :1
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target