Prerequisites
Ensure your Ubuntu system has a graphical desktop environment (e.g., GNOME, Xfce) installed. For server editions, install one first:
sudo apt update && sudo apt install ubuntu-desktop # For GNOME
# OR
sudo apt install xfce4 # For Xfce (lighterweight)
Update system packages and install essential tools:
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential curl wget git -y
1. Install TigerVNC Server
Install the TigerVNC standalone server and common components:
sudo apt install tigervnc-standalone-server tigervnc-common -y
2. Configure VNC Password
Set a secure VNC password (different from your system login password) for authentication:
vncpasswd
- Enter and confirm your password (max 8 characters).
- Skip the “view-only password” prompt unless you need read-only access.
3. Configure Desktop Environment for VNC
TigerVNC requires a startup script (~/.vnc/xstartup) to launch the desktop environment.
3.1 Generate xstartup File (if missing)
Run vncserver once to create the .vnc directory and default files:
vncserver
Press Ctrl+C to stop the server immediately after creation.
3.2 Edit xstartup for Your Desktop Environment
Open the xstartup file in a text editor (e.g., nano):
nano ~/.vnc/xstartup
Replace the content with the following (adjust for your desktop environment):
-
For GNOME (default on Ubuntu Desktop):
#!/bin/sh unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS xrdb $HOME/.Xresources vncconfig -iconic & gnome-session & -
For Xfce (lightweight alternative):
#!/bin/sh unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS xrdb $HOME/.Xresources startxfce4 &
Save the file (Ctrl+O, Enter, Ctrl+X) and make it executable:
chmod +x ~/.vnc/xstartup
4. Start the TigerVNC Server
Launch the VNC server with a specified display number (e.g., :1 for port 5901):
vncserver :1
- The first instance uses port
5901(:1=5900 + 1). - Check active sessions with:
vncserver -list
5. Configure Firewall (Allow VNC Traffic)
If UFW (Uncomplicated Firewall) is enabled, allow the VNC port (default: 5901 for :1):
sudo ufw allow 5901/tcp
sudo ufw enable # Enable firewall if not already active
6. (Optional) Set Up Systemd for Auto-Start
To ensure the VNC server starts at boot, create a systemd service file:
6.1 Create the Service File
sudo nano /etc/systemd/system/vncserver@.service
6.2 Add Configuration
Replace with your Ubuntu username and adjust the geometry/display settings as needed:
[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=
Group=
WorkingDirectory=/home/
PIDFile=/home//.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
6.3 Enable and Start the Service
Reload systemd, enable the service, and start it:
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service # Replace "1" with your display number
sudo systemctl start vncserver@1.service
7. Connect to the Ubuntu Desktop Remotely
On a remote computer (Windows/macOS/Linux), use a VNC client (e.g., RealVNC Viewer, TigerVNC Viewer) to connect:
- Open the client and enter the Ubuntu server’s IP address followed by the display number (e.g.,
192.168.1.100:1). - Enter the VNC password you set in Step 2.
- The remote desktop will load with your configured environment.
Troubleshooting Tips
- Port Conflicts: Ensure no other service uses the VNC port (default:
5901for:1). Check withnetstat -tulnp | grep 5901. - Black Screen: Verify the
xstartupfile has execute permissions (chmod +x ~/.vnc/xstartup) and matches your desktop environment. - Firewall Issues: Confirm UFW allows the VNC port (
sudo ufw status). - SSH Tunneling (Secure Connection): For added security, use SSH to forward the VNC port locally:
Then connect the VNC client tossh -L 5901:localhost:5901@ localhost:1.
By following these steps, you can securely share your Ubuntu desktop using TigerVNC and access it from any remote device.
以上就是关于“如何在Ubuntu上共享TigerVNC桌面”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm