Control your Raspberry Pi from Anywhere in the World with a Few Easy Steps
Learn how to access and control your Raspberry Pi remotely using Secure Shell (SSH) and the popular VNC Viewer software. This guide will help you set up remote access, connect to your Raspberry Pi fro …
Updated August 24, 2023
Learn how to access and control your Raspberry Pi remotely using Secure Shell (SSH) and the popular VNC Viewer software. This guide will help you set up remote access, connect to your Raspberry Pi from anywhere, and troubleshoot common issues.
If you want to operate your Raspberry Pi without being physically present at its location, you can use Secure Shell (SSH) to remotely access it from another computer or device over a network. Additionally, you can use VNC Viewer to see and interact with the graphical user interface of your Raspberry Pi’s desktop remotely. This guide will show you how to set up remote access using SSH and VNC Viewer on both Windows and macOS/Linux systems.
Setting Up Remote Access via SSH
- Enable SSH on your Raspberry Pi:
- Open the terminal on your Raspberry Pi and enter the following command to enable SSH:
sudo systemctl enable ssh
- Start the SSH service with this command:
sudo systemctl start ssh
- Open the terminal on your Raspberry Pi and enter the following command to enable SSH:
- Find the IP address of your Raspberry Pi:
- On your Raspberry Pi, run the following command in the terminal to display its network information:
ifconfig
- Note down the IPv4 address under wlan0 or eth0 (depending on whether you’re connected via Wi-Fi or Ethernet).
- On your Raspberry Pi, run the following command in the terminal to display its network information:
- Connect to your Raspberry Pi from another computer or device using an SSH client:
- On Windows, download and install PuTTY from https://www.putty.org/.
- On macOS or Linux, open a terminal and type the following command (replace
<IP address>
with your Raspberry Pi’s IPv4 address):ssh pi@<IP address>
- Enter
raspberry
as the password when prompted.
- To connect securely from another device, generate an SSH key pair on your local computer and copy the public key to your Raspberry Pi:
- On your local computer, run the following command in the terminal (press Enter when asked for a passphrase to leave it blank):
ssh-keygen -t rsa
- Copy the contents of
~/.ssh/id_rsa.pub
to~/.ssh/authorized_keys
on your Raspberry Pi:cat ~/.ssh/id_rsa.pub | ssh pi@<IP address> "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"
- On your local computer, run the following command in the terminal (press Enter when asked for a passphrase to leave it blank):
- Disable password authentication in
sshd_config
to enhance security:- On your Raspberry Pi, edit the SSH configuration file with this command:
sudo nano /etc/ssh/sshd_config
- Locate the line
#PasswordAuthentication yes
and change it toPasswordAuthentication no
. Save and exit the file. - Restart the SSH service for changes to take effect:
sudo systemctl restart ssh
- On your Raspberry Pi, edit the SSH configuration file with this command:
- Update your Raspberry Pi’s firewall settings to allow incoming SSH connections:
- Run this command on your Raspberry Pi to open port 22 (SSH) in
ufw
:sudo ufw allow 22/tcp
- Run this command on your Raspberry Pi to open port 22 (SSH) in
Now you can remotely access your Raspberry Pi using the IP address, username (pi
), and SSH key or password.
Setting Up Remote Desktop Access with VNC Viewer
- Install TightVNC server on your Raspberry Pi:
- Run this command in the terminal to update your package list and install TightVNC:
sudo apt-get update && sudo apt-get install tightvncserver
- Run this command in the terminal to update your package list and install TightVNC:
- Configure the VNC server:
- Run
vncserver
in the terminal, set a password when prompted, and configure any other settings you need.
- Run
- Install a VNC viewer on your local computer (e.g., TightVNC Viewer for Windows or macOS/Linux):
- Connect to your Raspberry Pi using the VNC viewer:
- Enter the IP address and port number (
<IP address>:1
) in the VNC viewer, and log in with the password you set earlier.
- Enter the IP address and port number (
You can now remotely access and control your Raspberry Pi’s desktop from any device on the network or internet.
Troubleshooting Remote Access
If you encounter issues connecting to your Raspberry Pi remotely, try the following troubleshooting steps:
- Check if SSH is running: Run
sudo systemctl status ssh
on your Raspberry Pi. If it’s not active, restart the service withsudo systemctl start ssh
. - Make sure port 22 is open on your router and firewall settings allow incoming connections to the Raspberry Pi.
- Verify that you’re using the correct IP address and credentials (username and password/key).
- Check if TightVNC server is running: Run
vncserver -list
on your Raspberry Pi to see a list of active sessions, orps aux | grep Xvnc
for processes. If it’s not running, start it withvncserver
. - Ensure you have the correct VNC viewer settings (IP address, port number, and password).
With these steps, you can access your Raspberry Pi remotely from anywhere in the world using SSH and VNC Viewer. Enjoy the convenience of managing your Raspberry Pi from afar!