Skip to content

Instantly share code, notes, and snippets.

@fliphess
Created August 28, 2018 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fliphess/3bf1fed4f823974a52ca199fb3233fb2 to your computer and use it in GitHub Desktop.
Save fliphess/3bf1fed4f823974a52ca199fb3233fb2 to your computer and use it in GitHub Desktop.
Setup a raspberry pi without screen attached

Headless setup raspberry pi

Get the image

Get the latest image and save it to disk:

# Desktop version
wget -O ~/raspbian.zip https://downloads.raspberrypi.org/raspbian_latest

# Lite version
wget -O ~/raspbian_lite.zip https://downloads.raspberrypi.org/raspbian_lite_latest 

Burn the image

Unzip the image:

unzip ~/raspbian*.zip

Burn the image to disk:

sudo dd bs=1m if=~/path_of_your_image.img of=/dev/rdiskn conv=sync

Mount the image and enable ssh and wifi configuration to be used from /boot

Mount the disk and navigate to the mounted /boot partition:

cd /Volumes/boot 

Enable ssh on boot:

touch ssh

Enable wifi:

export SSID="somewifi"
export WIFIPASS="assword"

cat <<EOF >> wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="$SSID"
    psk="$WIFIPASS"
}
EOF

Unmount the image

Unmount SD Card:

sudo umount -f /Volumes/boot

OR on mac:

diskutil unmount /Volumes/boot/

Now shove the sdcard up the back of the raspberry pi, attach power and wait for the pi to connect to wifi and make and ssh connection to raspberrypi.local:

ssh pi@raspberrypi.local -o PreferredAuthentications=password

Install when ssh access

User configuration

Create the user we'll use for SSH access:

sudo su 
adduser flip
echo 'flip ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/010_pi-nopasswd

Configure ssh access

mkdir /home/flip/.ssh

cat <<EOF  >> /home/flip/.ssh/authorized_keys
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKyoTp9EL+KwQzMUoITDO9r/0QljINBmWhsj17XNZmOe/11Q0SXN4sPu5yxW8i6Hlya2EeCNKd0rUuvJ795H2cU= /media/profiles/base/flip-20161030
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPCyAVgZd2VUxDhzi1d/qEost7l2/8gNQ/x0nOMxwjTCb3LgynNnJpWQCwN/q4Q9TQlUyHlEhGqynHUKL9t3owA= /media/profiles/thuis/flip-20161030
EOF

chmod 700 /home/flip/.ssh 
chmod 600 /home/flip/.ssh/authorized_keys 
chown -Rv flip:flip /home/flip/.ssh

Remove pi user

Login as flip, sudo to root and remove pi user:

deluser pi

Install packages

PACKAGES=(
    apt-transport-https
    arping
    autoconf
    automake
    bash
    bash-completion
    bind9-host
    bind9utils
    binutils
    bsdmainutils
    bsdutils
    build-essential
    bzip2
    ca-certificates
    cabextract
    ccache
    conntrack
    coreutils
    curl
    dnsutils
    file
    findutils
    fping
    ftp
    git
    gzip
    hostname
    htop
    ioping
    iotop
    ipcalc
    iproute
    iproute2
    iptables
    iputils-ping
    iputils-tracepath
    ipython
    less
    links
    lsof
    make
    makedev
    moreutils
    ncdu
    ncurses-base
    ncurses-bin
    ncurses-term
    net-tools
    netbase
    ngrep
    nload
    nmap
    procps
    psmisc
    psutils
    python3
    python3-apt
    python3-dev
    rsync
    screen
    sed
    slay
    socat
    strace
    tcpdump
    telnet
    tmux
    traceroute
    unzip
    vim
    virtualenv
    virtualenvwrapper
    wget
    zip
    build-essential
    libasound2-dev
    libvorbisidec-dev
    libvorbis-dev
    libflac-dev
    alsa-utils
    libavahi-client-dev
    avahi-daemon
)

apt update
apt dist-upgrade -y
apt install -y ${PACKAGES[@]}

Setup phat dac

If you are root, ctrl+D to regular user.

wget -O phatdac.sh https://get.pimoroni.com/phatdac 
bash phatdac.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment