Raspberry Pi – Stage 2 – Networking Remoting (Mac)

As I have limited display devices (TVs) in the home and there is always a battle with the kids the first thing I wanted to do with the RPi was set it up wirelessly and configure remote access through both command line and a screen viewer. This entry provides the step by step guidance to do this.

Credits:- Adafruit Learning

Pre-req: Before using this ensure your RPi is set up, see Raspberry Pi – Step 1 – Setup

Step 1 – Setting up Wireless

In order to set up wireless you first require a USB wireless dongle. I bought a cheap USB wifi dongle from Amazon, for £7.50 I figured I can’t go wrong, and was shocked at how easily it was to set up, so lets get started. Note if you buy a different dongle try and find one that supports the RTL8192cu chipset, as the drivers are built into the Occidentalis distro we’ve installed already.

  1. Boot the Raspberry Pi without the WiFi adapter plugged in.
  2. Open a Terminal session by clicking on the LXTerminal icon, and enter the following command into it:
    sudo nano /etc/network/interfaces
  3. This open will open an editor screen for the file you need to change.
    The two places where you need to make a change are on the last two lines.
    Change the SSID and PSK to match the name and password for your Wifi network.
    Ensure you keep the quotes around the information you enter.
  4. When you have finished press [ctrl]x. This will ask if you want to save the modified files.
    Press ‘Y’ and then Return to save the file with the same name.
  5. Shut down your Raspberry Pi, plug the WiFi adapter in and start it up again.
    You should find that the Raspberry Pi connects using the WiFi adapter as it boots up.

That’s it! now we can set up remoting.

Step 2 – Remote Access

My requirements are initially for ssh access so I can remotely access the command line and for a remote desktop capability, although as I develop I may resort just to command line.

The first step is to identify the IP Address of your RPi so you can access it, to do this run the following command in a terminal session and identfy the IP Address:

sudo ifconfig

SSH is a setting in the RPi config, which we covered in the initial blog entry. However if you’d like to check SSH is enabled follow the below steps.

  1. Open LX Terminal to get a terminal session
  2. Run
    sudo raspi-config
  3. Select the SSH option
  4. Select “Enable”
  5. Now switch move to a different machine and open a command prompt/terminal session
  6. run the following command in the terminal on your Mac (ApplicationsOtherTerminal) and replace 192.168.1.13 with your RPi IP Address found above.
    ssh -X pi@192.168.1.13
  7. If you receive any warnings just accept them
  8. Log in using the password “raspberry”
  9. This logs you in as the pi user.
  10. You can now access using an ssh client such as Putty

Remote Desktop Using VNC

These steps will show how to configure the VNC protocol to remote desktop onto your RPi from a Mac. Full steps and background can be found at Adafruit but I’m going to list each step I took here so you don’t need to jump around.

Configuring the RPi VNC Server

  1. Open a LX Terminal oraccess your RPi via ssh (as above)
  2. Enter the following command to install a VNC service, enter y when prompted
    sudo apt-get install tightvncserver
  3. Now run the vnc server using the following command
    vncserver : 1
  4. You will be promted for a password, it’s length is limited to 8, for ease we will use “raspberr” but you can change this
  5. Enter n when promted for a read only account
  6. That’s the VNC server running but we want it to auto start if we restart our RPi
  7. Enter the following command
    cd /home/pi
  8. cd into the config directory, note the . before the directory name indicates a hidden dir
    cd .config
  9. Create an autostart directory
    mkdir autostart
  10. move into the autostart directory
    cd autostart
  11. Now we need to create a new config file to autostart vnc, open nano to do this
    nano tightvnc.desktop
  12. Enter the following content into the empty file
    [Desktop Entry]
    Type=Application
    Name=TightVNC
    Exec=vncserver :1
    StartupNotify=false
  13. Press ctrl + X and then select y to save and exit the nano text editor
  14. That’s it! You can now access VNC using a VNC client such as VNCViewer

If you’re using a Mac then the Mac has a service called bonjour that can be used for remote desktop, the following steps are taken from 4DC5 and explain how to configure the Mac and RPi, note they assume that the above steps have been completed.

  1. On the RPi enter
    sudo apt-get install netatalk
  2. On the Mac open Finder, and hit ?K. Enter afp://192.168.0.22 (using the IP address of your RPi)
  3. On the RPi enter
    sudo apt-get install avahi-daemon
    sudo update-rc.d avahi-daemon defaults
  4. Now create a config file using nano
    sudo nano /etc/avahi/services/afpd.service
  5. Add the following content
    <?xml version="1.0" standalone='no'?>
    <!--*-nxml-*-->
    <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
    <service-group>
    <name replace-wildcards="yes">%h</name>
    <service>
    <type>_afpovertcp._tcp</type>
    <port>548</port>
    </service>
    </service-group>
  6. Enter Ctrl + X and enter y to save and exit the file
  7. Now restart the service
    sudo /etc/init.d/avahi-daemon restart
  8. On the Mac the RPi should be visible within the finder sidebar
  9. Now we need to configure tightvpn we installed earlier to work with the Mac protocol
  10. Open the vnc config file
    cd /etc/init.d
    
    sudo nano tightvncserver
  11. Add the following content to the file
    #!/bin/bash
    # /etc/init.d/tightvncserver
    #
    # Carry out specific functions when asked to by the system
    case "$1" in
    start)
        su pi -c '/usr/bin/vncserver -geometry 1440x900'
        echo "Starting VNC server "
        ;;
    stop)
        pkill vncserver
        echo "VNC Server has been stopped (didn't double check though)"
        ;;
    *)
        echo "Usage: /etc/init.d/blah {start|stop}"
        exit 1
        ;;
    esac
    exit 0
  12. Now enter the following commands to restart the server and apply the new settings
    sudo chmod +x tightvncserver
    sudo pkill Xtightvnc
    ps aux | grep vnc
    sudo /etc/init.d/tightvncserver start
    cd /etc/init.d
    sudo update-rc.d tightvncserver defaults
  13. Now configure the RPi to be visible to Bonjour, create a new config file
    sudo nano /etc/avahi/services/rfb.service
  14. Add the below content to the file
    <?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>
  15. Press Ctrl + X and then y to save and exit
  16. Finally, restart the daemon
    sudo /etc/init.d/avahi-daemon restart
  17. Now if you select your RPi in finder on the Mac there should be a Screen Share option

Your RPi now simply requires a power supply and you can access it from your Mac using Screen Share or SSH.

One thought on “Raspberry Pi – Stage 2 – Networking Remoting (Mac)”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.