Headless Raspberry Pi
Jul. 24th, 2014 08:11 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
A couple of weeks ago, on a bit of whim, I bought myself a Raspberry Pi as a bit of a toy. Having done this I promptly noticed a minor snag: my my total lack of USB input devices and the absence of HDMI ports on any of my monitors.
Set defaults like the timezone: Change the Pi to use a static IP address - this is unnecessary if using zero-configuration to publish addresses of services
Install the VNC and zero-configuration software:
Add the following definition files to the
Next create a script to automatically start VNC for the Create the necessary boot links for the script by running: Start the VNC server interactively to set a password and to ensure that all the necessary files exist: Reboot in the usual way: If everything has worked the system should come up again with its static IP address and should be offering a VNC session via zero-configuration
After a bit of thought, I realised that I was being a fool and that I could use my long-honed command line skills to set up a headless box in no time at all. Thus, I grabbed a copy of Raspbian, dd
'd it to my SD card, booted the Pi off the network, used ssh to install a VNC server, installed and configured Avahi to register the VNC with OS X, and used the Screen Sharing App on my iMac as my VNC client.
- Flash the SD card with Raspbian
- Connect the Pi to the network and boot it up
- Find the IP address assigned to the Pi — I queried my router's list of connected devices
- Connect to the default account:
ssh pi@<ip address>
- Change the default password immediately:
passwd
- Update everything:
-
sudo apt-get update
-
sudo apt-get upgrade
-
sudo apt-get dist-upgrade
-
sudo raspi-config
- Edit the network configuration file:
sudo vi /etc/network/interfaces
- Change the line "
iface eth0 inet dhcp
" toiface eth0 inet static
- Add your choice of address:
address <ip address>
- Set the netmask to match the address:
netmask <netmask>
- Set the gateway to your router
gateway <gateway address>
- Save the changes and quit the editor
-
sudo apt-get install tightvncserver
-
sudo apt-get install avahi-daemon
/etc/avahi/services
directory:
-
sudo vi /etc/avahi/services/multiple.service
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_device-info._tcp</type> <port>0</port> </service> <service> <type>_ssh._tcp</type> <port>22</port> </service> </service-group>
-
sudo vi /etc/avahi/services/rfb.service
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_rfb._tcp</type> <port>5901</port> </service> </service-group>
pi
user — it's easy enough to create a new user account and use this instead — by running: sudo vi /etc/init.d/tightvncserver
#!/bin/bash ### BEGIN INIT INFO # Provides: tightvncserver # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start VNC server for a user # Description: Allow remote VNC access for a user ### END INIT INFO VNCUSER=pi SERVERID=1 . /lib/lsb/init-functions server_start() { CMD="/usr/bin/tightvncserver :$SERVERID" if [[ `id -un` = $VNCUSER ]]; then $CMD > /dev/null 2>&1 elif [[ `id -u` = 0 ]]; then /bin/su - $VNCUSER -c "$CMD > /dev/null 2>&1" else /bin/false fi } server_stop() { pkill -U $VNCUSER "Xtightvnc" } server_status() { pgrep -U $VNCUSER "Xtightvnc" > /dev/null && \ echo "VNC is running for user $VNCUSER" || \ echo "VNC is not running for $VNCUSER" } case $1 in start) log_daemon_msg "Starting VNC for user $VNCUSER" "tightvncserver" server_start log_end_msg $? ;; stop) log_daemon_msg "Stopping VNC for user $VNCUSER" "tightvncserver" server_stop log_end_msg $? ;; restart) $0 stop $0 start ;; status) server_status ;; *) echo "usage: $0 {start|stop|restart|status}" exit 1 ;; esac exit 0
sudo update-rc.d tightvncserver defaults
tightvncserver :1
sudo shutdown -r now
On OS X, connections and zero-configuration can be tested using the "Go > Connect to Server..." menu in Finder and "Shell > New Remote Remote Connection" in Terminal
Easy!