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.
- Boot the Raspberry Pi without the WiFi adapter plugged in.
- Open a Terminal session by clicking on the LXTerminal icon, and enter the following command into it:
sudo nano /etc/network/interfaces
- 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. - 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. - 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.
- Open LX Terminal to get a terminal session
- Run
sudo raspi-config
- Select the SSH option
- Select “Enable”
- Now switch move to a different machine and open a command prompt/terminal session
- 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
- If you receive any warnings just accept them
- Log in using the password “raspberry”
- This logs you in as the pi user.
- 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
- Open a LX Terminal oraccess your RPi via ssh (as above)
- Enter the following command to install a VNC service, enter y when prompted
sudo apt-get install tightvncserver
- Now run the vnc server using the following command
vncserver : 1
- 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
- Enter n when promted for a read only account
- That’s the VNC server running but we want it to auto start if we restart our RPi
- Enter the following command
cd /home/pi
- cd into the config directory, note the . before the directory name indicates a hidden dir
cd .config
- Create an autostart directory
mkdir autostart
- move into the autostart directory
cd autostart
- Now we need to create a new config file to autostart vnc, open nano to do this
nano tightvnc.desktop
- Enter the following content into the empty file
[Desktop Entry] Type=Application Name=TightVNC Exec=vncserver :1 StartupNotify=false
- Press ctrl + X and then select y to save and exit the nano text editor
- 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.
- On the RPi enter
sudo apt-get install netatalk
- On the Mac open Finder, and hit ?K. Enter afp://192.168.0.22 (using the IP address of your RPi)
- On the RPi enter
sudo apt-get install avahi-daemon sudo update-rc.d avahi-daemon defaults
- Now create a config file using nano
sudo nano /etc/avahi/services/afpd.service
- 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>
- Enter Ctrl + X and enter y to save and exit the file
- Now restart the service
sudo /etc/init.d/avahi-daemon restart
- On the Mac the RPi should be visible within the finder sidebar
- Now we need to configure tightvpn we installed earlier to work with the Mac protocol
- Open the vnc config file
cd /etc/init.d sudo nano tightvncserver
- 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
- 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
- Now configure the RPi to be visible to Bonjour, create a new config file
sudo nano /etc/avahi/services/rfb.service
- 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>
- Press Ctrl + X and then y to save and exit
- Finally, restart the daemon
sudo /etc/init.d/avahi-daemon restart
- 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)”