vnc - dwilson2547/wiki_demo GitHub Wiki
- 1. What is VNC?
- 2. How VNC Works
- 3. VNC Components
- 4. Setting Up VNC
- 5. Securing VNC
- 6. VNC vs. RDP vs. SSH
- 7. Common VNC Clients and Servers
- 8. Troubleshooting VNC
- 9. Advanced VNC Features
- 10. VNC Security Best Practices
- 11. VNC Alternatives
- 12. Summary
VNC (Virtual Network Computing) is a graphical desktop-sharing system that allows you to remotely control another computer over a network. It transmits the keyboard and mouse inputs from the client to the server and updates the display from the server to the client in real-time. VNC is platform-independent, meaning you can control a Linux machine from Windows, macOS, or even a mobile device.
VNC operates on the RFB (Remote Frame Buffer) protocol, which is optimized for remote display. Here’s how it works:
- VNC Server: Runs on the machine you want to control. It captures the screen, accepts input, and sends updates to the client.
- VNC Client (Viewer): Runs on the machine you’re using to control the server. It sends keyboard/mouse inputs and displays the remote screen.
- RFB Protocol: The protocol used to transmit input and display updates between the server and client.
-
Initiate Connection:
- The VNC client connects to the VNC server on a specified port (default: 5900 + display number, e.g.,
5901
for display:1
). - Example:
vncviewer server-ip:5901
- The VNC client connects to the VNC server on a specified port (default: 5900 + display number, e.g.,
-
Authentication:
- The server prompts the client for a password or other authentication method (e.g., SSH tunneling).
-
Session Establishment:
- Once authenticated, the server starts sending screen updates to the client.
- The client sends keyboard and mouse inputs to the server.
-
Real-Time Interaction:
- The server updates the client’s display in real-time as changes occur (e.g., window movements, typing).
- Purpose: Hosts the remote desktop session.
-
Examples:
-
TigerVNC:
vncserver
(Linux) -
RealVNC:
vncserver-x11
(Linux/Windows) -
TightVNC:
tightvncserver
(Windows/Linux)
-
TigerVNC:
-
Configuration:
- Set a password:
vncpasswd
- Start the server:
vncserver :1 -geometry 1920x1080 -depth 24
- Kill the server:
vncserver -kill :1
- Set a password:
- Purpose: Connects to the VNC server to control it.
-
Examples:
-
TigerVNC Viewer:
vncviewer server-ip:5901
- RealVNC Viewer: GUI-based client for Windows/macOS.
- Remmina: Linux client with RDP/VNC support.
-
TigerVNC Viewer:
-
Usage:
vncviewer 192.168.1.100:5901
- Purpose: Transmits input and display updates between client and server.
-
Features:
- Efficient: Only transmits changes to the screen (not the entire display).
- Cross-Platform: Works on any OS with a VNC client/server.
- Extensible: Supports extensions for features like file transfer or clipboard sharing.
sudo apt update
sudo apt install tigervnc-standalone-server tigervnc-common
sudo yum install tigervnc-server
-
Set a Password:
vncpasswd
- Prompts you to set a password for VNC access.
-
Start the VNC Server:
vncserver :1 -geometry 1920x1080 -depth 24
- Starts a VNC server on display
:1
with a resolution of 1920x1080 and 24-bit color.
- Starts a VNC server on display
-
Kill the VNC Server:
vncserver -kill :1
-
Create a systemd service file:
sudo nano /etc/systemd/system/[email protected]
Add the following (adjust
User
andExecStart
):[Unit] Description=Start TigerVNC server at startup After=syslog.target network.target [Service] Type=simple User=yourusername PAMName=login PIDFile=/home/%u/.vnc/%H%i.pid ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :' ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -depth 24 -localhost no ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
-
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable [email protected] sudo systemctl start [email protected]
vncviewer server-ip:5901
- Use TightVNC Viewer, RealVNC Viewer, or Remmina.
- Enter the server’s IP and port (e.g.,
192.168.1.100:5901
).
VNC traffic is not encrypted by default. Use SSH to create a secure tunnel:
ssh -L 5901:localhost:5901 user@server-ip
- Connect to
localhost:5901
with your VNC client.
- Use a firewall (e.g.,
ufw
oriptables
) to allow VNC access only from trusted IPs:sudo ufw allow from 192.168.1.100 to any port 5901
- Avoid simple passwords. Use a strong, unique password for VNC access.
- Only run VNC servers on displays you need:
vncserver -kill :2
- Some VNC servers (e.g., RealVNC) support TLS encryption. Enable it in the server configuration.
Feature | VNC | RDP (Remote Desktop Protocol) | SSH |
---|---|---|---|
Platform Support | Cross-platform (Linux, Windows, macOS) | Primarily Windows (with limited Linux/macOS support) | Cross-platform (Linux, Windows, macOS) |
Protocol | RFB | RDP | SSH |
Encryption | Optional (use SSH tunneling) | Built-in encryption | Built-in encryption |
Performance | Slower (transmits screen updates) | Faster (optimized for Windows) | Not for graphical sessions |
Use Case | Remote graphical desktop access | Remote Windows desktop access | Remote command-line access |
Port | 5900 + display number | 3389 | 22 |
Tool | Type | Platform Support | Notes |
---|---|---|---|
TigerVNC | Server/Client | Linux, Windows, macOS | Open-source, lightweight |
RealVNC | Server/Client | Linux, Windows, macOS, Raspberry Pi | Commercial and free versions |
TightVNC | Server/Client | Windows, Linux | Optimized for slow connections |
UltraVNC | Server/Client | Windows | Supports file transfer and chat |
Remmina | Client | Linux | Supports VNC, RDP, SSH, and more |
Vinagre | Client | Linux | KDE-based VNC client |
Apple Screen Sharing | Client | macOS | Built-in VNC client for macOS |
- Cause: VNC server is not running or blocked by a firewall.
-
Fix:
- Start the VNC server:
vncserver :1
- Check the firewall:
sudo ufw allow 5901
- Start the VNC server:
- Cause: VNC server crashed or display settings are incorrect.
-
Fix:
- Restart the VNC server:
vncserver -kill :1 && vncserver :1
- Adjust resolution/color depth:
vncserver :1 -geometry 1280x720 -depth 16
- Restart the VNC server:
- Cause: Incorrect password or misconfigured authentication.
-
Fix:
- Reset the VNC password:
vncpasswd
- Check the VNC server logs for errors.
- Reset the VNC password:
- Cause: High latency or insufficient bandwidth.
-
Fix:
- Reduce color depth:
vncserver :1 -depth 16
- Use a faster compression method (e.g.,
Tight
orZRLE
in TigerVNC).
- Reduce color depth:
- Cause: SSH server is not running or misconfigured.
-
Fix:
- Start the SSH server:
sudo systemctl start sshd
- Verify the tunnel:
ssh -L 5901:localhost:5901 user@server-ip
- Start the SSH server:
- Some VNC clients (e.g., UltraVNC) support file transfer between local and remote machines.
- Copy and paste text between local and remote machines.
- Configure VNC to span multiple monitors:
vncserver :1 -geometry 3840x1080 # For two 1920x1080 monitors side-by-side
- Use SSH tunneling or a VPN to securely access VNC over the internet.
- Example with SSH:
ssh -L 5901:localhost:5901 user@your-server-ip
- Connect your VNC client to
localhost:5901
.
- Connect your VNC client to
- Run a VNC server without a physical display (e.g., on a headless Raspberry Pi):
vncserver :1 -geometry 1920x1080 -depth 24
- Use
x11vnc
for headless setups:sudo apt install x11vnc x11vnc -storepasswd /etc/x11vnc.pass x11vnc -rfbauth /etc/x11vnc.pass -foreground -o /var/log/x11vnc.log
-
Always Use SSH Tunneling:
- Encrypts VNC traffic to prevent eavesdropping.
ssh -L 5901:localhost:5901 user@server-ip
-
Restrict Access with Firewalls:
- Allow VNC access only from trusted IPs.
sudo ufw allow from 192.168.1.100 to any port 5901
-
Use Strong Passwords:
- Avoid simple passwords. Use a password manager to generate strong passwords.
-
Disable Unused VNC Displays:
- Kill unused VNC servers to reduce attack surface.
vncserver -kill :2
-
Enable TLS Encryption:
- Use VNC servers that support TLS (e.g., RealVNC).
-
Regularly Update VNC Software:
- Keep your VNC server and client updated to patch vulnerabilities.
sudo apt update && sudo apt upgrade tigervnc-standalone-server
-
Monitor VNC Logs:
- Check logs for unauthorized access attempts.
tail -f ~/.vnc/*:1.log
-
Use One-Time Passwords (OTP):
- Integrate VNC with Google Authenticator or Duo Security for 2FA.
Tool | Protocol | Use Case | Notes |
---|---|---|---|
RDP | RDP | Windows remote desktop access | Built into Windows; faster than VNC |
X2Go | NX | Linux remote desktop access | Faster than VNC for Linux |
NoMachine | NX | Cross-platform remote desktop | High performance, proprietary |
Chrome Remote Desktop | Proprietary | Remote access via browser | Easy to set up; requires Google account |
TeamViewer | Proprietary | Remote support and access | Commercial; no setup required |
- VNC allows remote graphical access to a computer over a network.
- VNC Server runs on the machine you want to control; VNC Client connects to it.
- RFB Protocol transmits screen updates and inputs between client and server.
- Security is critical: Use SSH tunneling, firewalls, and strong passwords.
- Performance tips: Adjust resolution, color depth, and compression for slower connections.
- Alternatives: RDP (Windows), X2Go (Linux), or NoMachine (cross-platform).