I typically connect to my Raspberry Pis via SSH from my main machine, a Mac. This is fine for pretty much all of the tasks I perform on the Pis, but it only provides access to the commmand line. That’s not a problem for me, but I nonetheless wondered whether I might be able to access the Pi’s desktop UI remotely too.
It turns out that you can, using VNC (Virtual Network Computing). VNC is a standard, widely supported way of securely presenting a GUI remotely over a network connection. You need a suitable server running on the machine that will be sharing its desktop, and a client app to present that desktop on the computer you’re accessing the remote machine from. The client relays your mouse and keyboard input back to the remote computer.
sudo apt-get install tightvncserver
When the software has downloaded and installed, it’s ready to run:
You will be asked to set up an remote access control password and to enter it a second time, as verification. You’ll also be asked if you’d like to enter a password for view-only access. This is optional; I just entered ‘n’ for no.
The server is now running and, if you set it up using SSH, you can log out of the Pi if you wish.
TightVNC doesn’t supply a client for Mac OS X, though it does offer a client for Windows and a cross-platform client that runs under Java. I’m not a fan of cross-platform tools — you tend to lose the benefits of your preferred OS — so I wondered if there was a native Mac OS X VNC client. There is and it comes free with your Mac, though you might never have seen it before.
Apple has long provided Apple Remote Desktop (ARD), a tool for remotely accessing Mac desktops. Over the years, it has gained support for a variety of remote access technologies, including VNC.
ARD doesn’t live in the Applications folder — it’s actually buried deep in the System folder — but it can be launched via finder: just hit Command-K to invoke the standard Mac ‘Connect to Server’ dialog. Here, enter
and click on ‘Connect’. The ‘vnc’ at the start sets the protocol you’ll use to connect to your remote Pi, which is identified here by its Bonjour (mDNS) name: its hostname (typically set using raspi-config followed by
.local). The number after the colon is the port through which the communication takes place. tightvncserver defaults to VNC port 1. 5900 is the base VNC port, hence 5901.
You’ll now be asked for the remote desktop’s access password. This is the password you set through tightvncserver, not your regular Pi password (they can be the same, of course, though it’s perhaps best to use different ones, for tighter security). You can choose to save the password in the keychain for faster access next time.
All going well, you’ll now see your Pi’s X desktop appear in a window provided by an ARD app called Screen Sharing. Depending on your Pi (the faster the better) and the quality of your network connection (ditto), the desktop is quite useable. You might not want to do all of your Pi work this way, but it’s acceptable for occasional use.
When you’re done, you can open shut down your Pi (using the Terminal or the Pi menu) or select ‘Close’ from Screen Sharing’s Connection menu.
By default tightvncserver establishes an 800 x 400 desktop, but you can change that using the -geometry switch. You can set the colour depth using the -depth switch too. For example:
tightvncserver -geometry 1920x1080 -depth 24
Of course, the bigger the desktop and the higher the colour depth, the more data that needs to be sent to Pi to Mac, and the slower and less responsive the remote system will feel. Experiment to find the size you prefer. I usually stick with the default. I also set my Pis to boot to the command line and not to auto log in, so they don’t run separate X sessions in the background.