In a previous post, we saw how to set up WiFi on the Raspberry Pi and how to wirelessly connect to it via an SSH client called PuTTY. PuTTY is a great way to access the command line, but you can’t use it to access the desktop. In this tutorial, I’ll show you how to access your Raspberry Pi’s desktop or command line from anywhere in the world. After setting up a remote desktop connection, you’ll be able to access your Pi from you iPhone, iPad, or laptop from anywhere with an internet connection.
We’ll do this by first setting up a remote desktop application on the computer you want to access the Pi from. Then, we’ll set up a port forward on the router the Pi is connected to, so it can be accessed from other computers outside of your home network. You’ll need to have access to the Pi’s command prompt, and also know the local IP address of the Pi. See this tutorial if you need help with that.
Update! Raspbian Jessie operating systems released after 9-23-16 now come with the Pixel desktop. Pixel uses a different remote desktop service than earlier Raspbian desktop versions, so I’ve created separate sections for setting up both…
Setup for Raspbian Pixel Desktop
Use this section if your Raspbian OS was released after 9-23-16…
RealVNC server is included in Raspbian Jessie releases after 9-23-16. All we need to do on the Pi is enable VNC in the raspi-config menu. Enter sudo raspi-config at the command prompt to access it.
Then select “Interfacing Options” from the menu:
Then select “VNC”, to enable VNC:
Now reboot the Pi with sudo reboot.
Next we need to install RealVNC Viewer on the computer you want to access the Pi from. Download RealVNC Viewer here and open the .exe file. It’s a portable application, so you don’t need to install it:
If you know the IP address of your Pi, enter it into the address bar at the top of the window. If you don’t know it, you can find it with Advanced IP Scanner.
Now press Enter and you’ll be prompted for the Pi’s username and password:
If this is the first time connecting to the Pi with RealVNC, you’ll get a security warning. Just press Continue to get past it:
The Raspbian Desktop will open up in a VNC Viewer window:
Setup for Older Raspbian Desktops
Use this section if your Raspbian OS was released before 9-23-16…
Older versions of Raspbian don’t include RealVNC, but we can install a similar service called XRDP that works well too. Log into your Raspberry Pi with PuTTY, and enter sudo apt-get install xrdp to install the XRDP service:
That’s all you need to do on the Raspberry Pi side.
Now, on your Windows computer, open up the Remote Desktop Connection application. This is a Windows app, so it should already be on your computer. Now enter the local IP address of your Raspberry Pi:
Click connect, and you’ll be prompted to enter the Pi’s username and password:
If you haven’t changed it yet, the username is pi and the password is raspberry.
Click “Ok” and you’ll be logged into the Rasbian desktop:
Configure for Access Outside Your Home Network
The remote desktop connections above are great and work well as long as you only connect to the Raspberry Pi from your home network. However, it won’t work outside your home network. To connect to your Pi from other computers outside of your home network, you need to forward a port in your router’s configuration settings. This will tell your router to send the connection to the Pi’s local IP address whenever you connect to a port from outside of your home network.
To do this, enter your router’s configuration menu by entering the default gateway IP address into the search bar of your internet browser, in my case it’s 10.0.0.1.
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:
Then login to your router’s configuration page. If you don’t know the username and password, try admin for the username and password for the password:
Once you’re inside your router’s configuration menu, look for a setting that says “Port Forwarding”. It may be under advanced settings:
In my case, I click “Add Service” to add a new port 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’ve figured out how to add a new port forward, enter the 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 App, we need to forward port 3389. Enter 3389 as both the “Start Port” and the “End Port”. Click save to save the connection.
Now we need to find your router’s public IP address. Just Google “what’s my IP” and you can find sites that will tell you for free:
Write this down, then open up the Remote Desktop Connection application in Windows. In the “Computer” field, enter your router’s public IP address, followed by a colon and the port forwarded in the above steps. For example, if your public IP is 22.214.171.124, and you forwarded port 3389, you would enter 126.96.36.199:3389 here:
Using this address you’ll be able to connect to your Raspberry Pi from anywhere outside of your home network.
Remote Desktop from iOS Devices
The Windows Remote Desktop App is perfect if you want to access the Pi from a Windows machine, 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 easy:
Add a new connection:
Enter your home router’s public IP address and the port you forwarded:
Then make another connection with the local IP address of your Pi:
Tap “Done” and select the connection you want to use:
You’ll probably want to create two connections. A connection with the Pi’s local IP address can be used when you’re on your home network. Another connection with your router’s public IP address and forwarded port can be used when you’re away from home.
Here’s a video showing you how to set up everything in the post above:
That should about cover it, but if you’re having trouble setting anything up, just leave a comment below and I’ll see if I can help. And don’t forget to subscribe if you’d like to see more tutorials like this one!
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.