In a previous post, we learned how to set up a WiFi dongle and access the Raspbian command prompt via an SSH client called PuTTY. PuTTY is a great application for accessing the command line in Raspbian from another computer, but you can’t use it to access the Raspbian desktop (GUI). To access the Raspbian GUI from another computer, we need to configure it to work with a remote desktop application. This will allow us to access our Raspberry Pi desktop (or the command line) from anywhere in the world as long as we have a computer with an internet connection. To do this, we must first install a service on the Raspberry Pi called xrdp. Log into your Raspberry Pi with PuTTY, and enter sudo apt-get install xrdp to install the xrdp service:
That is all we need to do on the Raspberry Pi side. Now, go to your Windows computer (see below for iPhone, iPad, and Macs). Click the “Start” button or Windows button, and type “Remote Desktop Connection” to search for the Remote Desktop Application. It is worthwhile to create a desktop shortcut for it now to easily access it in the future. Open up the Remote Desktop Application, and enter your local IP address for your Raspberry Pi connected over WiFi:
Click connect, and you will be connected to the xrdp login screen for the Raspberry Pi:
Enter your username and password here, they are the same as the PuTTY login if you haven’t changed them yet (username= pi and password= raspberry). Click “Ok” and you will be logged into the Rasbian GUI:
Configure for Access Outside Your Home Network
This is all great, and works very well as long as we only connect to out Raspberry Pi in our home WiFi network. Since we only used our local IP address in the connection, it will not work outside of our home network. To be able to connect to the Raspberry Pi from anywhere in the world, we first need to forward a port in our router configuration, which will tell our router to send the connection to our Raspberry Pi’s local IP address whenever we connect to a specific port from outside of our network. To do this, we will need to enter our home router’s configuration menu, which can be accessed by entering the “Default Gateway IP address” into the search bar of your internet browser, in my case it is 10.0.0.1 (hint: if you don’t know the username/password, try username= admin and password= password):
If you don’t know what your Default Gateway IP Address is, you can find it by opening up the command prompt in Windows, and entering ipconfig:
Once you are inside your router’s configuration menu, look for an option for “Port Forwarding”. It may be under advanced settings:
In my case, I click “Add Service” to add a new port to forward. Your case may be different depending upon which type of router you have. Consult your user manual or search online for instructions pertaining to your specific router model. Once you have figured out how to add a port forward, enter details of the connection:
The “Service Type” should be TCP/UDP. Where it says “Server IPv4 Address”, enter the local IP address of your Raspberry Pi (in my case it’s 10.0.0.106). Now enter which ports need to be forwarded. For the Windows Remote Desktop Application, we need to forward port 3389. Enter 3389 as both the “Start Port” and the “End Port”. Click save to save the connection. Now, all connections “calling” your public IP and port 3389 will be forwarded to your Raspberry Pi (see below).
For the next step, we need to know your public IP address. Just Google “what’s my IP” and you can find sites that will tell you for free if you don’t know it already.
Take note of your public IP address, then go back to the Remote Desktop Connection application in Windows. In the “Computer” field, enter your public IP address, followed by a colon and the port forwarded in the above steps. For example, if your public IP is 188.8.131.52, and you forwarded port 3389, you would enter 184.108.40.206:3389 here:
Using this connection, you will be able to connect to your Raspberry Pi from anywhere outside of your home network. This is available on PC’s running Windows, but if you use an iOS device, you can install the Microsoft Remote Desktop App, “RD Client” and access the Raspbian desktop from your iPhone, iPad, or Mac. The set up is very easy, just add a new connection:
You will probably need to create two connections. One connection will need to be made with your local IP address (10.0.0.106 in my case), which you use when you are at your home network. Another connection will need to be made with your port forwarded address (220.127.116.11:3389 in my case) which you will use when you are away from home.
Here’s a video showing you how to do the remote connection:
That should do it, but if you’re having trouble connecting, just leave a comment below and I will see if there is anything else you should try to get it going.
Need an easy-to-use way to design circuits and layout PCBs?
Try EasyEDA, a free circuit design software that also offers low cost, high quality PCB manufacturing.