Skip to content

Instantly share code, notes, and snippets.

@anoff
Last active November 19, 2023 11:34
Show Gist options
  • Save anoff/db58cb7d5d1e1ecda060ef9f622e9083 to your computer and use it in GitHub Desktop.
Save anoff/db58cb7d5d1e1ecda060ef9f622e9083 to your computer and use it in GitHub Desktop.
Links and tips on how to get a pi set up for developing remotely (#rsyn, #ssh, #mac, #pi)

How to set up a raspberry pi for remote development

Links and tips on how to get a pi set up for developing remotely (#rsyn, #ssh, #mac, #pi)

Preparations

required (used)

  • Raspberry Pi, SD Card, 5V micro-USB
  • Macbook Pro w/ ethernet adapter
  • WiFi with internet connection

not required

  • monitor
  • keyboard

get raspbian lite

  1. get the latest -lite image from raspberrypi.org
  2. lite is a smaller bundle without all the GUI components
  3. flash it on SD card with something like ether
  4. place a file named ssh in the /boot directory of the SD card 1  2. run touch /Volumes/boot/ssh  2. this will enable SSH on the pi for one boot, make it count
  5. if you fail just re-add the file for another try

get connectivity up

  1. connect pi via ethernet to macbook
  2. give the adapter a manual IP address (make sure you don't overlap with the subnet in your wifi network)
  3. let's try with ip: 192.168.1.222, subnet 255.255.255.0, router: blank
  4. add a dns record e.g. the main google dns 8.8.8.8
  5. find the device on the network using nmap
  6. run nmap -p22 --open 192.168.0.0/22 where -p22 only scans for SSH ports and /22 scans for the range 192.168.0.0 to 192.168.3.255  2. if you can not identify the pi in the found devices try increasing the ip range by further reducing the /22 prefix  2. in my case the pi ends up on 192.168.2.3 (dunno why..)
  7. enable internet sharing for the wireless to the ethernet connection
  8. preferences > sharing > internet sharing 1

secure the pi

create ssh keypair and install on pi

# on mac/host machine
cd ~/.ssh
# create new key pair
ssh-keygen -b 4096 -f id_pi -N '' -C 'raspberry pi login key'
# add fingerprint to known hosts
ssh-keyscan -H 192.168.2.3 >> ~/.ssh/known_hosts
# copy public key to pi
ssh-copy-id -i id_pi.pub [email protected]
# you need to enter the password for the pi user which by default is 'raspberry' (we'll fix this later)

remove password on pi

The following commands will

  • forbid password login on SSH
  • change the SSH port 2221
  • change the user password interactively
# execute on mac
cd ~/.ssh
# create connection to pi
ssh -i id_pi [email protected]
# change ssh port to 2221
sudo sed -i 's/^#*Port .*/Port 2221/' /etc/ssh/sshd_config
# disable password authentication on ssh
sudo sed -i 's|[#]*PasswordAuthentication yes|PasswordAuthentication no|g' /etc/ssh/sshd_config
# restart ssh service
sudo service ssh restart
# change pi password
passwd # < interactive (make sure to pick an incredibleawesomepipassword 👀)
# re logon
exit
ssh -i id_pi -p 2221 [email protected]
# update packages
sudo apt-get update && apt-get upgrade
sudo apt-get install rsync

customize shit

  • expand filesystem
  • set locale
sed -i 's/#*alias ll=.*$/alias ll="ls -ahl"/g' .bashrc
sudo raspi-config

install node

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
source .bashrc
nvm install v7
# add yarn
curl -o- -L https://yarnpkg.com/install.sh | bash

get node-serialport running

According to the node-serialport docs the ARM platform is partially supported. With node v7.4.0 and serialport v4.0.7 it currently seems to work.

connecting to new devices

  • go into interactive mode with bluetoothctl
# activate controller
power on
# activate agent
agent on
scan on
# wait....
devices

Backup

Backing up a pi config with a mac is explained here

On Mac, you can also use the standard dd tool with a slightly different syntax:

dd if=/dev/rdiskx of=/path/to/image bs=1m Where /dev/rdiskx is your SD card.

(using rdisk is preferable as its the raw device - quicker)

To find out which disk your device is type diskutil list at a command prompt - also, you may need to be root; to do this type sudo -s and enter your password when prompted.

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# locale
export LANG=en_US.UTF-8
# prompt style
GREEN=$(tput setaf 2);
YELLOW=$(tput setaf 3);
WHITE=$(tput setaf 7);
PINK=$(tput setaf 5);
BLACK=$(tput setaf 0);
PS1="${PINK}\u@\w${BLACK}👾 \[\e[1m\]$[\e[0m\] ";
# some more ls aliases
alias ll="ls -ahl"
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export NVM_DIR="/home/pi/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
export PATH="$HOME/.yarn/bin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment