Raspberry Pi

How to Remotely Access Raspberry Pi Through VNC Over SSH (Remote SSH Tunneling)

Raspberry Pi is a single-board minicomputer that allows you to remotely access it from another computer through VNC and SSH. By default, VNC directly allows you to access Raspberry Pi without enabling the SSH service. While, the SSH service is only used to remotely connect to Raspberry Pi terminal from another computer in a secure manner. However, if you combine both these services for a remote connection that is using Raspberry Pi desktop through VNC over SSH, you will be able to increase the privacy of your device.

In this guide, you will learn:

Why Is it Useful to Remotely Access Raspberry Pi Through VNC Over SSH

How to Enable SSH on Raspberry Pi

How to Remotely Access Raspberry Pi Through VNC Over SSH on Mac or Linux

How to Remotely Access Raspberry Pi Through VNC Over SSH on Windows

Conclusion

Why Is it Useful to Remotely Access Raspberry Pi Through VNC Over SSH

The VNC over SSH commonly termed as remote SSH tunneling is a secure way that allows you to connect to Raspberry Pi without entering the IP address and default VNC port number 5900. This makes your system secure because even if someone knows your device IP address, he still won’t be able to access your device without knowing the port on which it is forwarded.

How to Enable SSH on Raspberry Pi

By default, SSH service is disabled on Raspberry Pi system to protect the security of your device. However, you can enable it on Raspberry Pi using:

How to Enable SSH on Raspberry Pi from GUI

You can enable SSH on Raspberry Pi from GUI using the following steps:

Step 1: Go to Raspberry Pi application menu by clicking on the Raspberry Pi shape icon at the top left corner of the screen:

Step 2: Then go to the Preferences menu and navigate to the Raspberry Pi Configuration option:

Step 3: Go to the Interfaces tab, then select the SSH option and move the toggle button to right, this will enable the SSH on Raspberry Pi:

How to Enable SSH on Raspberry Pi from Terminal

If you are using the Raspberry Pi Lite version, you can enable the SSH on Raspberry Pi from the terminal using the following steps.

Step 1: Open Raspberry Pi configuration using the following command:

sudo raspi-config

Ensure using the above raspi-config command with sudo because you will encounter the “Script must be run as root” error, if you don’t use it:

Step 2: Go to the Interfaces Options by pressing the down key from your keyboard:

Step 3: Choose SSH from the Interfaces option:

Step 4: Choose the Yes option by pressing the Enter or Spacebar button from the keyboard:

You will see a confirmation window telling you that SSH server is enabled on your Raspberry Pi system:

How to Remotely Access Raspberry Pi Through VNC Over SSH on Mac or Linux

The method to remotely access Raspberry Pi through VNC over SSH can be done easily from the terminal. However, the terminal method will only work for Mac or Linux based systems and doesn’t require installing any third-party tool. Instead, you can use the following steps to complete the Raspberry Pi remote access through VNC over SSH on Mac or Linux:

Step 1: Execute SSH Command

Open your terminal on Mac or Linux system and execute the following statement by assigning the port number in place of new_port_no according to your choice:

ssh -L new_port_no:localhost:default_port_no -N -f -l username Host_IP_Address

Note: If 5900 in not your default_port_no, and you have changed it by mistake, then enter the desired port number on which your VNC is operating. You can confirm this by accessing the Raspberry Pi on VNC through IP address.

Step 2: Install and Open VNC Viewer on Mac or Linux

You must install a VNC Viewer on a Mac or Linux system to access Raspberry Pi remotely, you can follow here to download and install VNC Viewer based on your system. After the installation, open VNC Viewer on your system and enter the address localhost with the new port number you have previously set in the above step:

Step 3: Access Raspberry Pi Remotely

Click on the Continue button as soon as you enter the server address on VNC Viewer:

Then enter your Raspberry Pi username and password in the credential’s boxes:

Once you enter the correct credentials for your Raspberry Pi, you will see the Raspberry Pi desktop on VNC Viewer at your assigned port address:

This ensures that the Raspberry Pi device has been accessed successfully through a local host address without the default port 5900.

How to Remotely Access Raspberry Pi Through VNC Over SSH on Windows

On Windows, the above method to remotely access Raspberry Pi through VNC Over SSH may not work. You will need to install an SSH Client PuTTY on your system then use the following steps to apply tunneling and access Raspberry Pi through VNC over SSH on Windows:

Step 1: Open PuTTY on Windows

First, open PuTTY client on your Windows system and enter the username and host IP address of your Raspberry Pi system:

username@Host_IP_Address

Note: The IP Address of Raspberry Pi can be found through the terminal via hostname -I command.

Step 2: Save the PuTTY Session

Write the session name in the Saved Sessions box and save it using the Save button:

Step 3: Forward Port in PuTTY on Windows

Now navigate to Connection settings, expand it then head towards the SSH settings and select the Tunnels option:

Step 4: Enter Source Port and Destination

You must enter the new port number in the Source port box, and IP address with the default VNC port number in the Destination box. Once done, click on the Add button to add it in the Forward ports box:

Step 5: Open the PuTTY Session

Now, head towards the Session option and click on the Open button to open the current PuTTY session:

Step 6: Open Event Log

To check the session activities, right click on the PuTTY session, select the Event Log:

You will see that your local port is forwarded to the default address used to access Raspberry Pi on VNC:

Step 7: Install and Open VNC Viewer on Windows

Now ensure you have installed VNC Viewer or other VNC related client on your Windows system. Then use the address localhost with the assigned port number you set in the previous step:

Step 8: Access Raspberry Pi Remotely through VNC Over SSH

Now, click on the Continue button to allows VNC to open the VNC session:

Then use the Raspberry Pi’s username and password in the VNC credentials options:

Once done successfully, you will be able to access the Raspberry Pi desktop through VNC over SSH by tunneling:

This is how you can remotely access your Raspberry Pi system without IP address and default port number and make your device secure from unauthorized access.

Conclusion

You can remotely access Raspberry Pi through VNC over SSH by executing the ssh command with the desired port number, default port number, username and password. However, this method can only be done on a Mac or Linux terminal. For Windows, you have to use PuTTY application that allows you the option to perform remote SSH tunneling. A step-by-step guide for remote access Raspberry Pi through VNC over SSH is provided in the above sections of this guide. You can choose the method based on the system you are using and secure your VNC remote access with Raspberry Pi through SSH.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.