Access your Raspberry Pi from Anywhere with a VNC Connection
Learn how to connect remotely to your Raspberry Pi and control it from another device using a virtual network computing (VNC) connection. …
Updated September 8, 2023
Learn how to connect remotely to your Raspberry Pi and control it from another device using a virtual network computing (VNC) connection.
Before we begin, make sure you have completed the following steps:
- Set up your Raspberry Pi with a stable internet connection.
- Update your Raspberry Pi software by running
sudo apt-get update && sudo apt-get upgrade
. - Install a VNC server on your Raspberry Pi by running
sudo apt-get install tigervnc-standalone-server
. - Create a new user account for the VNC session with
adduser vncuser
. - Set a password for the VNC user by running
passwd vncuser
. - Generate a random password for your VNC connection by running
pwgen -s 12 1
. - Start the VNC server and enable it to start on boot by running:
vncserver :1 -geometry 1920x1080 -depth 24 -pixelformat rgb565 -passwordfile ~/.vnc/passwd
sudo systemctl enable vncserver@1.service
Now that your Raspberry Pi is set up to accept VNC connections, let’s connect from another device:
Connecting to Your Raspberry Pi Remotely
There are several ways to connect remotely to your Raspberry Pi, but we will focus on two popular methods: using the ssh
command and a VNC client.
Method 1: Using SSH
SSH (Secure Shell) is a protocol that allows you to securely log in to another computer and run commands as if you were sitting at the console. To connect to your Raspberry Pi via SSH, follow these steps:
- Open a terminal window on your local computer.
- Type
ssh vncuser@<raspberry_pi_ip> -p 5901
and replace<raspberry_pi_ip>
with the IP address of your Raspberry Pi. You can find this by runningifconfig
on your Raspberry Pi or checking your router’s DHCP client list. - Enter the password you set for the VNC user when prompted.
You should now have a command line interface to your Raspberry Pi. To exit the SSH session, type exit
.
Method 2: Using a VNC Client
A VNC client allows you to view and control your Raspberry Pi’s graphical desktop remotely. Here are the steps to connect using a VNC client on Windows or macOS:
- Download and install a VNC viewer, such as TightVNC (Windows) or TigerVNC (macOS).
- Open the VNC viewer and enter the IP address of your Raspberry Pi in the “Host” field.
- Set the port to
5901
and click “Connect”. - Enter the password you set for the VNC connection when prompted.
You should now have a graphical interface to your Raspberry Pi, allowing you to interact with it as if you were sitting in front of it. To disconnect from the VNC session, press Ctrl + Alt + End
and click “Disconnect” or close the window.
That’s it! You can now connect to your Raspberry Pi remotely using either SSH or a VNC client. This allows you to access your Raspberry Pi from anywhere with an internet connection, making it a powerful tool for remote monitoring and control.