keepcalculator

06 Numbers and Powers

SSH vs VNC for Raspberry Pi: Which to Use?

Card No. 06·16911 · Updated · Standard formula, shown below

For remote access to a Raspberry Pi, choose SSH for command-line tasks and VNC for a full graphical desktop. SSH is faster, lighter, and more secure, while VNC is necessary when you need to interact with the Pi’s GUI. This article explains the differences, when to use each, and how to set them up.

What Is SSH?

SSH (Secure Shell) is a network protocol that lets you open a secure terminal session on a remote device. On a Raspberry Pi, SSH gives you a text-based command line where you can run any command as if you were sitting at the Pi with a keyboard and monitor. It encrypts all traffic between your computer and the Pi, so passwords and data are protected from eavesdropping.

SSH is built into Linux, and the Raspberry Pi OS has it available but disabled by default (you enable it by placing a file named ssh on the boot partition or via raspi-config). You connect using a client like ssh pi@raspberrypi.local from a terminal (Linux/macOS) or PuTTY on Windows.

What Is VNC?

VNC (Virtual Network Computing) is a protocol that shares the graphical desktop of a remote machine. With VNC, you see the Pi’s desktop as a window on your local computer and can control the mouse and keyboard. The Raspberry Pi OS includes RealVNC Server, which can be enabled in the Interfacing Options of raspi-config. You then connect with a VNC viewer (e.g., RealVNC Viewer, TightVNC) to the Pi’s IP address or hostname.

VNC transmits screen updates, which means it uses more bandwidth and CPU than SSH. It is ideal when you need to use graphical applications like the desktop environment, LibreOffice, or the Thonny Python IDE.

Key Differences Between SSH and VNC

The main difference is the interface: SSH is text-only, VNC is graphical. This leads to several practical differences:

  • Performance: SSH is extremely fast even over slow networks because it sends only text. VNC sends pixel data, so it can be laggy over Wi-Fi or the internet.
  • Security: SSH is inherently secure with encryption. VNC can be encrypted if you use an SSH tunnel or a VPN, but by default VNC traffic is unencrypted (RealVNC on Raspberry Pi OS does support encryption when using their cloud service).
  • Resource usage: SSH uses minimal memory and CPU on the Pi. VNC requires the desktop environment to run, consuming RAM and CPU, which can slow down a Pi Zero or older models.
  • Use cases: SSH is perfect for headless setups, server administration, scripting, and installing software. VNC is needed for GUI applications or when you want to see the desktop for troubleshooting.

When to Use SSH

Use SSH when you need to perform any task that can be done from the command line. This includes:

  • Updating the system: sudo apt update && sudo apt upgrade
  • Editing configuration files with nano or vim
  • Installing packages: sudo apt install python3-pip
  • Running scripts or services
  • Transferring files with scp or rsync
  • Monitoring logs or system status

If you are building a web server, a home automation hub, or a network ad blocker (like Pi-hole), SSH is all you need. It is also the most reliable way to access the Pi when the desktop is not running or when you are troubleshooting a boot issue.

When to Use VNC

VNC is the choice when you need the graphical desktop. Examples include:

  • Using the full desktop environment (e.g., for a media center or a lightweight desktop PC)
  • Running GUI applications like the Chromium browser or GIMP
  • Teaching or demonstrating the Pi’s desktop to someone else
  • When you are more comfortable with a mouse and windows than a terminal

VNC is also handy for initial setup if you are not familiar with the command line, though it is generally better to learn SSH for efficiency.

How to Choose: SSH or VNC?

To decide, ask yourself: do I need to see the desktop? If the answer is no, use SSH. If yes, use VNC. But there are more nuanced considerations:

  • Network speed: Over the internet, SSH is far more responsive. VNC over the internet often requires a VPN or port forwarding and can be frustratingly slow.
  • Pi model: On a Pi Zero or Pi 1, VNC will be sluggish. SSH is the only practical option for serious work on those models.
  • Security: SSH is safer to expose to the internet (if you use key authentication and disable password login). VNC should never be directly exposed to the internet without a VPN or SSH tunnel.
  • Ease of use: VNC is easier for beginners because it shows the familiar desktop. SSH requires learning basic commands.

You can also use both: SSH for administrative tasks and VNC for occasional GUI needs. Many users enable both and switch depending on the task.

Common Problems and Solutions

Here are typical issues you might encounter and how to fix them:

  • Can’t connect via SSH: Ensure SSH is enabled (sudo raspi-config -> Interfacing Options -> SSH). Check the Pi’s IP address with hostname -I. If using hostname, make sure mDNS (Bonjour) is available on your client.
  • VNC connection refused: Enable VNC in raspi-config (Interfacing Options -> VNC). Check that the VNC server is running: systemctl status vncserver-x11-serviced. Restart it with sudo systemctl restart vncserver-x11-serviced.
  • VNC is very slow: Reduce the screen resolution or color depth in the VNC server settings. Use a wired Ethernet connection instead of Wi-Fi. On a Pi Zero, consider using a lightweight desktop like LXDE (which is default) and avoid heavy animations.
  • SSH password not accepted: Make sure you are using the correct username (default is pi on Raspberry Pi OS). If you changed the password, use that. Check that the keyboard layout is correct when typing the password.
  • VNC shows a blank screen: This often happens when the Pi is not connected to a monitor. Configure VNC to use a virtual display: in raspi-config, under Display Options, set Resolution to a specific value (e.g., 1280×720) instead of “Default”. Alternatively, edit /boot/config.txt to add hdmi_force_hotplug=1 and hdmi_group=1 and hdmi_mode=16.

Security Considerations

Security is a critical factor when exposing any remote access service to the internet. SSH is generally safe if you follow best practices:

  • Use SSH keys instead of passwords: generate a key pair on your computer and copy the public key to the Pi’s ~/.ssh/authorized_keys.
  • Disable password authentication in /etc/ssh/sshd_config (set PasswordAuthentication no) after setting up keys.
  • Change the default user from pi to something else, or at least use a strong password.
  • Do not expose SSH to the internet unless you have a firewall and strong authentication. Consider using a VPN (like WireGuard or OpenVPN) instead.

VNC is less secure by default. If you must use VNC over the internet, always tunnel it through SSH or a VPN. On Raspberry Pi OS, RealVNC offers an end-to-end encrypted cloud connection if you sign in with a RealVNC account, but that requires trusting a third party. For local network use, VNC is generally acceptable, but still consider enabling encryption if available.

Alternatives to SSH and VNC

There are other ways to access a Raspberry Pi remotely:

  • RDP (Remote Desktop Protocol): You can install xrdp on the Pi to use Windows Remote Desktop. It is often faster than VNC and supports multiple sessions, but it requires the desktop to be running.
  • Web-based terminals: Tools like ttyd or shellinabox let you access a terminal through a web browser. This is useful if you cannot install an SSH client.
  • Cloud-based remote access: Services like RealVNC Connect, TeamViewer, or AnyDesk offer easy setup and work through firewalls, but they rely on third-party servers and may have licensing restrictions for commercial use.
  • Serial console: For low-level debugging, you can connect to the Pi’s UART pins with a USB-to-serial cable. This works even if the network is down.

Frequently Asked Questions

Can I use both SSH and VNC at the same time?

Yes, you can run both services simultaneously. SSH and VNC use different ports (22 and 5900 by default) and do not interfere. Many users keep SSH always enabled and start VNC only when needed.

Which one is faster, SSH or VNC?

SSH is much faster because it transmits only text. VNC transmits screen pixels, so it is slower and more bandwidth-intensive. For a responsive experience over the internet, SSH is the clear winner.

Is VNC secure enough for local network use?

On a trusted local network, VNC is generally acceptable, but it is not encrypted by default. If you are concerned about other devices on the network sniffing traffic, use an SSH tunnel or enable VNC encryption if your server supports it.

Can I use VNC to access the Pi from a phone or tablet?

Yes, there are VNC viewer apps for Android and iOS (e.g., RealVNC Viewer, VNC Viewer for Mobile). You can also use SSH client apps like Termius or JuiceSSH for terminal access from mobile devices.

Do I need a monitor connected to the Pi to use VNC?

No, you can use a “virtual display” by setting a fixed resolution in raspi-config or by adding hdmi_force_hotplug=1 to /boot/config.txt. This allows VNC to work without a physical monitor.

What is the default username and password for Raspberry Pi OS?

The default username is pi and the default password is raspberry. However, recent versions of Raspberry Pi OS require you to set a custom password during first boot, so the default may not apply.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →