Easy Way to Remote into a Raspberry Pi

It’s pretty easy to setup remote desktop access to a Raspberry Pi without opening up ports on your router. You can use this approach if you want to access your pi while traveling, or just around the corner at the coffee shop.

  1. Install xrdp on your pi.
    sudo apt-get install xrdp
  2. Edit the xrdp config file at /etc/xrdp/xrdp.ini and change the setting for crypt_level to ‘high’. xrdp will now use 128 bit encryption. Then restart the service.
    sudo service xrdp restart
  3. Install ngrok. For Raspbian 8 (Jessie), I used the ARM download.
    wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
    unzip ngrok-stable-linux-arm.zip -d /usr/bin
  4. Sign up for an account at ngrok. This is required to create a tcp tunnel.
  5. Create a tcp tunnel for port 3389, which xrdp uses for remote desktop.
    ngrok tcp 3389
  6. In terminal, ngrok will show you the forwarding URL. This URL can also be found in your ngrok account under “Status”. Once outside your home network, you can drop this URL (remove the “tcp://”) into a Remote Desktop client, and you should see the xrdp login window. After logging in, you’ll have access to your pi.

ngrok tunnels can be dropped in the case of loss of connectivity, power outage, etc. So to always have access to your pi, you can use a shell script like this one.

#!/bin/bash

output=$(curl -s http://localhost:4040/api/tunnels)
#echo "$output"
if [ -z "$output" ]
then
  echo "Tunnel down. Starting new tunnel..."
  nohup ngrok tcp 3389 &
  echo "Tunnel started."
else
  echo "Tunnel running."
fi

exit 0
Advertisements
  1. No trackbacks yet.

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

%d bloggers like this: