首页主机资讯Ubuntu VNC如何安装VNC服务器

Ubuntu VNC如何安装VNC服务器

时间2025-10-04 06:30:03发布访客分类主机资讯浏览1323
导读:Installing a VNC Server on Ubuntu: A Step-by-Step Guide VNC (Virtual Network Computing enables remote access to your Ub...

Installing a VNC Server on Ubuntu: A Step-by-Step Guide
VNC (Virtual Network Computing) enables remote access to your Ubuntu system’s graphical desktop. Below is a structured guide to installing and configuring a VNC server on Ubuntu, optimized for reliability and security.

1. Update System Packages

Before installing software, refresh your system’s package repository to ensure you get the latest versions:

sudo apt update &
    &
     sudo apt upgrade -y

2. Install VNC Server and Supporting Software

For Ubuntu, the recommended VNC server is TigerVNC (or tightvncserver for lightweight needs). Install it along with a desktop environment (e.g., XFCE for better performance on servers):

# Install TigerVNC server and XFCE desktop (replace with your preferred desktop)
sudo apt install tigervnc-standalone-server tigervnc-common xfce4 xfce4-goodies -y
  • Key Notes:
    • XFCE is lightweight and ideal for servers; replace with ubuntu-desktop if you prefer the default GNOME environment.
    • tigervnc-common provides essential utilities for VNC configuration.

3. Set a VNC Password

Configure a password for VNC access (required for all connections). The password must be 6–8 characters long:

vncpasswd
  • The password is encrypted and stored in ~/.vnc/passwd.
  • Important: This is not your system user password—keep it secure.

4. Configure the VNC Server

a. Customize Desktop Startup

Edit the ~/.vnc/xstartup file to define the desktop environment launched when connecting via VNC. For XFCE:

nano ~/.vnc/xstartup

Replace the file’s content with:

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
  • Why?: Ensures the correct desktop environment starts. Without this, you may see a blank screen.
  • Save changes (Ctrl+O, Enter, Ctrl+X) and make the file executable:
    chmod +x ~/.vnc/xstartup
    

b. Create a Systemd Service (Optional but Recommended)

For automatic startup at boot and easier management, create a systemd service:

sudo nano /etc/systemd/system/vncserver@:1.service

Add this configuration (replace your_username with your actual username):

[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=your_username
PAMName=login
PIDFile=/home/your_username/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 >
     /dev/null 2>
    &
    1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :1
ExecStop=/usr/bin/vncserver -kill :1

[Install]
WantedBy=multi-user.target
  • Key Parameters:
    • -depth 24: Sets color depth (24-bit for best quality).
    • -geometry 1920x1080: Defines screen resolution. Adjust to your preference.

5. Start and Enable the VNC Server

Reload systemd to apply the new service, then start and enable the VNC server:

# Reload systemd to recognize the new service
sudo systemctl daemon-reload

# Start the VNC server (display :1 = port 5901)
sudo systemctl start vncserver@:1.service

# Enable auto-start at boot
sudo systemctl enable vncserver@:1.service
  • To check the server status:
    sudo systemctl status vncserver@:1.service
    

6. Configure the Firewall

If your Ubuntu system uses UFW (Uncomplicated Firewall), allow traffic to the VNC port (default: 5901 for display :1):

sudo ufw allow 5901/tcp
sudo ufw reload
  • Note: If you change the display number (e.g., :2), adjust the port to 5902 (5900 + display number).

7. Connect to the VNC Server

Use a VNC client (e.g., TigerVNC Viewer, RealVNC, or Remmina) on your local machine. Enter the server’s IP address and port (e.g., 192.168.1.100:5901) and authenticate with the password set in Step 3.

Troubleshooting Tips

  • Black Screen: Ensure ~/.vnc/xstartup is correctly configured and executable.
  • Connection Refused: Verify the VNC server is running (sudo systemctl status vncserver@:1.service) and the firewall allows the port.
  • Resolution Issues: Modify the -geometry parameter in the systemd service or vncserver command.

By following these steps, you’ll have a secure and functional VNC server on Ubuntu, enabling remote access to your desktop environment from any compatible client.

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: Ubuntu VNC如何安装VNC服务器
本文地址: https://pptw.com/jishu/719674.html
Compton配置Ubuntu提升图形性能秘诀 Ubuntu Swap关闭会有什么影响

游客 回复需填写必要信息