Sub topic 11
VNC: cross-platform screen sharing
This chapter assumes you know basic networking terms (IP address, port, firewall) and have used both a Windows and a Linux desktop. It covers what Virtual Network Computing (VNC) is, how it differs from RDP, how to use it, and what commonly goes wrong. It also covers how to secure it for the A+ Core 2 exam.
What VNC is
Virtual Network Computing (VNC) is a remote desktop system that shares a screen over the network. A VNC server runs on the computer you want to control. A VNC viewer (the client) runs on the computer you sit at. The two talk using the Remote Framebuffer (RFB) protocol.
VNC works at the level of pixels. The server sends pictures of screen regions to the viewer. The viewer sends back keyboard and mouse events. Because it does not depend on the operating system's window system, VNC runs on Windows, macOS, Linux, and even some embedded devices and single-board computers.
Common implementations include RealVNC, TightVNC, TigerVNC, and UltraVNC. macOS also has a built-in VNC-compatible service called Screen Sharing.
VNC compared with RDP
On the exam you will often choose between VNC and RDP. The key difference is what you see.
| Feature | VNC | RDP |
|---|---|---|
| Default port | TCP 5900 (display :0), 5901 for :1, and so on | TCP 3389 |
| Platforms | Windows, macOS, Linux, others | Server built into Windows Pro and Server editions. Clients exist for most platforms |
| What you see | Usually the same screen the local user sees (shared) | Usually a separate session. The local screen locks |
| Method | Sends screen pixels | Sends drawing instructions and uses session features |
| Built-in encryption | Depends on product. The base protocol has weak or no encryption | Yes, by default |
| Best for | Helping a user while watching their screen. Mixed-OS environments | Administering Windows machines and servers |
Because VNC shows the shared console, it suits help-desk work where you and the user look at the same desktop. RDP usually takes over the machine and logs the local user out of view, which is poor for "show me what you see" troubleshooting.
How a VNC connection works
- The VNC server listens on a TCP port. Display number 0 uses port 5900, display 1 uses 5901, and so on.
- The viewer connects to the server's IP address or host name and the display or port.
- The server asks for authentication, usually a password or a system account.
- After authentication, the server sends screen updates and accepts input.
A worked example
Suppose a user on a Linux desktop needs help, and you work from a Windows laptop. RDP is not an option because the Linux machine does not run a Windows RDP server. VNC fits.
On the Linux machine, a technician installs and starts a VNC server. With TigerVNC, the following starts a virtual desktop on display 1, which listens on port 5901:
vncserver :1On the first run it asks you to set a password. You can then check that the server is listening:
ss -tln | grep 5901From the Windows laptop, you open a VNC viewer and enter 192.168.1.50:1 (or 192.168.1.50::5901, depending on the viewer). After you enter the password, the desktop appears.
Note that vncserver :1 creates a separate virtual desktop. To share the screen the user is actually looking at, you need a server that shares the physical display, such as x11vnc or the desktop's built-in sharing feature.
Security: the main weakness
The original VNC design has security problems you must know.
- Weak or missing encryption. Many VNC setups send screen data and keystrokes without encryption. Anyone who can capture traffic may read them. Some products encrypt the password exchange only.
- Weak authentication. Classic VNC password authentication uses a short password, and many products truncate it to 8 characters.
- Exposure to the internet. Port 5900 and nearby ports are scanned constantly. A VNC server open to the internet, especially with no password, is a common cause of compromise.
- Shared console. Anyone who connects sees what the local user sees, including open documents and passwords on screen.
Ways to secure VNC
- Do not expose VNC ports directly to the internet. Block TCP 5900 and higher at the perimeter firewall.
- Connect through a VPN so the VNC traffic travels inside an encrypted tunnel.
- Tunnel VNC through SSH. The viewer connects to a local port that SSH forwards to the server.
- Use a product that supports TLS encryption and individual user accounts.
- Use a strong, unique password. Never leave the password blank.
- Limit who can connect, for example by restricting the source IP addresses in the host firewall.
- Ask for the user's consent when connecting to a user's desktop, and close the server when the session ends.
Here is an SSH tunnel that forwards a local port to the VNC server. The viewer then connects to localhost:5901, and the VNC data travels inside the encrypted SSH connection:
ssh -L 5901:localhost:5901 [email protected]Common problems and how to fix them
| Symptom | Likely cause | Fix |
|---|---|---|
| Connection refused | The VNC server is not running, or you used the wrong port | Start the server. Check the display number and port with `ss -tln` or `netstat -an` |
| Connection times out | A firewall blocks TCP 5900 or the route is wrong | Allow the port on the host firewall. Test with ping and a port test |
| Authentication fails | Wrong password, or the viewer and server use incompatible security types | Reset the password. Update both sides or choose a common security type |
| Slow or choppy display | Low bandwidth or high color depth and resolution | Lower color depth, use compression, or reduce the resolution |
| Black or gray screen | The server shares a virtual display with no desktop running, or the user logged out | Start a desktop session, or use a server that shares the physical display |
| Cannot connect from outside | Network address translation (NAT) hides the host | Use a VPN or SSH tunnel rather than port forwarding |
Choosing VNC on the exam
Pick VNC when the question mentions any of these:
- A mix of Windows, macOS, and Linux machines.
- A technician needs to see and share the same screen as the user.
- A lightweight, open standard remote desktop tool.
Pick a different tool when the scenario calls for these:
- RDP for managing Windows with a separate session.
- SSH when only a command line is needed.
- A VPN when you need access to a whole private network.
Exercise
A help-desk technician must troubleshoot a macOS laptop while the user watches the same screen. The technician works from a Windows PC. Which remote technology fits, and what default TCP port does it use? Name one way to protect the session when it crosses the internet.
Show answer
VNC (macOS Screen Sharing is VNC-compatible), which defaults to TCP 5900. Protect it by connecting through a VPN or by tunneling it through SSH, rather than exposing port 5900 to the internet. Using a strong password and TLS-capable software also helps.
Exercise
A technician starts a VNC server on display :2 of a Linux host. Which TCP port should a firewall rule allow for that display, and why is a direct internet rule a poor choice?
Show answer
Port 5902, because the port is 5900 plus the display number. A direct internet rule is poor because VNC often lacks strong encryption and authentication, and exposed VNC ports are scanned and attacked constantly. Use a VPN or SSH tunnel instead.