Installing and Configuring VNC on Ubuntu
VNC (Virtual Network Computing) enables remote access to an Ubuntu system’s graphical desktop. Below is a structured guide to installing, configuring, and securing a VNC server on Ubuntu.
1. Update System Packages
Before installing VNC software, update your system’s package list to ensure compatibility with the latest versions:
sudo apt update
2. Install VNC Server and Desktop Environment
For a lightweight and efficient setup, use TigerVNC (recommended) with the XFCE desktop environment (less resource-intensive than GNOME):
sudo apt install tigervnc-standalone-server tigervnc-common xfce4 xfce4-goodies -y
- TigerVNC: A high-performance VNC server with encryption support.
- XFCE: A minimal desktop environment ideal for remote access (avoids lag on slower networks).
3. Set a VNC Password
Configure a password for VNC authentication (required for all connections). The password must be between 6–8 characters long:
vncpasswd
- Enter and confirm your password. The encrypted password will be saved to
~/.vnc/passwd.
4. Configure the VNC Startup File
Customize the ~/.vnc/xstartup file to launch the XFCE desktop when the VNC server starts. This file defines the session environment:
nano ~/.vnc/xstartup
Replace the existing content with the following (for XFCE):
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
- Key Lines:
unset SESSION_MANAGER: Prevents session management conflicts.exec startxfce4: Launches the XFCE desktop.
- Save changes (
Ctrl+O,Enter) and exit (Ctrl+X). - Make the file executable:
chmod +x ~/.vnc/xstartup
5. Start the VNC Server
Launch the VNC server with a specified display number (e.g., :1). The display number corresponds to a TCP port (5900 + display number; :1 = port 5901):
vncserver :1 -geometry 1920x1080 -depth 24
- Parameters:
:1: Display number (adjust as needed, e.g.,:2for port 5902).-geometry 1920x1080: Sets the remote desktop resolution.-depth 24: Configures color depth (24-bit for full color).
- The server will output connection details (e.g., IP address and port) to the terminal.
6. Configure the Firewall
If your Ubuntu system uses UFW (Uncomplicated Firewall), allow traffic to the VNC port (default: 5901 for :1):
sudo ufw allow 5901/tcp
sudo ufw reload
- Verify the rule was added:
sudo ufw status
7. (Optional) Enable Auto-Start at Boot
To ensure the VNC server starts automatically after a system reboot, create a Systemd service file:
sudo nano /etc/systemd/system/vncserver@.service
Add the following content (replace your_username with your actual username and :1 with your display number):
[Unit]
Description=VNC Server for user %u at display %i
After=network.target
[Service]
Type=simple
User=your_username
WorkingDirectory=/home/your_username
ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
Save and exit. Then, enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service # Replace "1" with your display number
sudo systemctl start vncserver@1.service
8. Connect to the VNC Server
On a remote computer, use a VNC client (e.g., RealVNC, TightVNC, or TigerVNC Viewer) to connect to your Ubuntu system:
- Enter the server’s IP address and port (e.g.,
192.168.1.100:5901for:1). - When prompted, enter the VNC password you set in Step 3.
- The remote desktop (XFCE) will load, allowing full control of the Ubuntu system.
Troubleshooting Common Issues
- Black Screen: Ensure
~/.vnc/xstartuphas executable permissions (chmod +x ~/.vnc/xstartup) and uses the correct desktop environment (e.g.,startxfce4for XFCE). - Port Conflicts: Verify no other service is using the VNC port (5901 by default) using
sudo netstat -tulnp | grep 5901. - Firewall Blocking: Double-check UFW rules (
sudo ufw status) to confirm port 5901 is allowed. - Resolution Issues: Adjust the
-geometryparameter in thevncservercommand (e.g.,1280x720for smaller screens).
This guide provides a secure and functional VNC setup for Ubuntu, enabling remote desktop access with minimal overhead. For advanced security (e.g., SSH tunneling), consider encrypting VNC traffic using SSH to prevent unauthorized access.
以上就是关于“Ubuntu VNC如何安装和配置”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm