Setting up a Raspberry Pi

From Spivey's Corner
Jump to: navigation, search

Steps to set up a Raspberry Pi for ssh access on the local network, without ever needing to connect a keyboard or monitor to the Pi. These instructions were prepared using a Pi 1 model B and checked on a Pi 3, but other Pi's should be almost the same.

(These instructions require a Linux machine, so the first part is of no use to those with only a Windows machine; and if you have a Linux machine, you can use QEMU anyway and don't need a Pi. With a Windows machine, you can enable ssh by creating a file on the VFAT partition, and initially at least work with a wired connection.)

$ unzip 2017-03-02-raspbian-stretch-lite.zip
$ rm 2017-03-02-raspbian-stretch-lite.zip
  • Insert an SD card, then unmount it and copy the image across (substitute the device name of your card for /dev/sdX).
$ sudo umount /dev/sdX1
$ sudo dd if=2017-03-02-raspbian-stretch-lite.img of=/dev/sdX bs=4M
  • Mount the two partitions of the SD card
$ mkdir boot root
$ sudo mount /dev/sdX1 boot
$ sudo mount /dev/sdX2 root
  • Create an empty file boot/ssh
$ sudo touch boot/ssh
  • Edit a file with sudo nano root/etc/networks/interfaces and change it to contain the following text
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-ssid "........"
    wpa-psk "........"

(substitute your own WiFi details where shown).

  • Unmount the two partitions, remove the SD card and put it in the Pi, and power up the Pi.
  • I have a BT Home Hub that automatically resolves the names of nodes connected on the local network with DHCP, so that makes finding the Pi and logging in a bit easier. You might have to visit the router config page and look at the list of attached devices, then maybe use a numeric IP address.
$ ssh raspberrypi -l pi
pi@raspberrypi's password: raspberry
pi@raspberrypi:~ $
  • Immediately change the password.
pi@raspberrypi:~ $ passwd
Changing password for pi.
(current) UNIX password: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
  • Update Linux
pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get upgrade
  • Set the time zone
pi@raspberrypi:~ $ sudo dpkg-reconfigure tzdata
  • Make an account in your own name
pi@raspberrypi:~ $ sudo adduser mike
...
Enter new UNIX password: <password>
Retype new UNIX password: <password>
...
  • Allow yourself to use sudo
pi@raspberrypi:~ $ sudo addgroup mike sudo
  • Change the hostname
pi@raspberrypi:~ $ sudo sed -i s/raspberrypi/omicron/ /etc/hosts /etc/hostname
  • Reboot
pi@raspberrypi:~ $ sudo reboot

Now log in with ssh as yourself.

$ ssh omicron
  • Install needed software.
mike@omicron:~ $ sudo apt-get install mercurial tcl ocaml-nox
  • Clone the Bitbucket repository.
mike@omicron:~ $ hg clone http://spivey.oriel.ox.ac.uk/hg/compilers
  • Build Keiko (not really needed for Lab 4) and the library modules.
mike@omicron:~ $ (cd compilers/keiko; make)
mike@omicorn:~ $ (cd compilers/lib; make)
  • Build Lab 4.
mike@omicron:~/compilers/keiko $ cd compilers/lab4
mike@omicron:~/compilers/lab4 $ make
mike@omicron:~/compilers/lab4 $ make pas0.o
  • Run the tests.
mike@omicron:~/compilers/lab4 $ make test1

An alternative

Personal tools

Variants
Actions
Navigation
Tools