How to display your Raspberry Pi’s desktop on a Mac

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.

Pi screen sharing

My Pi Zero’s desktop within my Mac desktop

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.

The Raspberry Pi Foundation recommends a specific VNC server, tightvncserver, written by TightVNC Software. You can install in the usual way:

sudo apt-get install tightvncserver

When the software has downloaded and installed, it’s ready to run:

tightvncserver

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

vnc://pi.local:5901

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.

Pi Screen Sharing

Point to your Pi using the standard ‘Connect to Server’ dialog

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.

Pi Screen Sharing

Connect Screen Sharing to your Pi desktop server

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.

Advertisements

5 thoughts on “How to display your Raspberry Pi’s desktop on a Mac

  1. the default bonjour name is ‘raspberrypi’ so you need to put in “vnc://raspberrypi.local:5901” or “vnc://[ip address of pi]:5901”

    the ip address is likely to be 192.168.1.xxx

  2. In minibian I can remote VNC, however it doesn’t ‘share’ the root desktop user screen (i.e. gives me a new instance) any ideas how to solve this? X11 config mods or etc?? Great posting, thanks for sharing!

  3. Why does my Mac loose the tightvncserver connection?
    Once I loose it I have great difficulty getting back in, what am I doing wrong?
    Please note that I am a beginner to all of the Raspberry Pi things.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s