Connecting Ubuntu VNC to Other Devices: A Step-by-Step Guide
To connect to another device (e.g., a Windows PC, macOS machine, or another Linux system) using VNC from an Ubuntu system, you’ll need to configure the Ubuntu machine as a VNC client (to initiate the connection) and the target device as a VNC server (to accept the connection). Below is a structured guide covering both scenarios:
The Ubuntu system will use a VNC client to connect to the remote server. Install a client like Remmina (recommended for its flexibility) or TightVNC Viewer:
sudo apt update
sudo apt install remmina tightvncviewer -y
Remmina is a graphical client with support for multiple protocols (VNC, RDP, SSH), while tightvncviewer is a lightweight command-line tool.
The target device (Windows, macOS, or Linux) must run a VNC server to share its desktop. Below are configurations for common platforms:
If the target is another Ubuntu system, follow these steps to set up a VNC server:
tigervnc-standalone-server (lightweight and secure) or tightvncserver:sudo apt update
sudo apt install tigervnc-standalone-server tigervnc-common -y
vncpasswd and enter a password (at least 6 characters). This password is used for client authentication.~/.vnc/xstartup file to specify the desktop environment (e.g., GNOME, XFCE). For GNOME (Ubuntu default):nano ~/.vnc/xstartup
Add the following lines (replace with your preferred environment if needed):#!/bin/sh
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
exec /etc/X11/Xsession ubuntu-xsession
Save the file and make it executable:chmod +x ~/.vnc/xstartup
:1 for port 5901):vncserver :1 -geometry 1920x1080 -depth 24
To stop the server later, use:vncserver -kill :1
:1) through the firewall:sudo ufw allow 5901/tcp
sudo ufw reload
On a Windows PC, install a VNC server like RealVNC or TightVNC:
ipconfig in Command Prompt).macOS has a built-in screen-sharing feature that supports VNC:
System Settings > Network).Once the target device is configured as a VNC server, use the Ubuntu client to initiate the connection:
<target_IP>:<display_number> (e.g., 192.168.1.100:1 for a Windows PC or 10.0.0.5:5901 for an Ubuntu server).Run the following command in the Ubuntu terminal, replacing <target_IP> and <display_number>:
vncviewer <target_IP>:<display_number>
For example, to connect to a Windows PC at 192.168.1.100 with display :1, use:
vncviewer 192.168.1.100:1
Enter the VNC password when prompted.
ssh -L 5901:localhost:5901 user@target_IP
Then connect to localhost:5901 using your VNC client.By following these steps, you can securely connect your Ubuntu system to other devices using VNC, enabling remote access to their desktop environments.