温馨提示×

ubuntu vnc怎么远程

小樊
62
2026-09-07 05:13:25
栏目: 智能运维

在 Ubuntu 上通过 VNC 远程桌面,一般步骤如下(以最常见的 TightVNC / TigerVNC + Xfce 为例,稳定、轻量)。


一、Ubuntu 服务端配置

1. 安装桌面环境(如果服务器没有图形界面)

sudo apt update
sudo apt install xfce4 xfce4-goodies

2. 安装 VNC Server

sudo apt install tigervnc-standalone-server

3. 设置 VNC 密码

vncpasswd

密码保存在 ~/.vnc

4. 配置 VNC 启动桌面

编辑或创建:

nano ~/.vnc/xstartup

写入以下内容:

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

赋予执行权限:

chmod +x ~/.vnc/xstartup

5. 启动 VNC Server

vncserver :1 -geometry 1920x1080 -depth 24
  • :1 → 端口 5901
  • :2 → 端口 5902

查看运行状态:

vncserver -list

二、防火墙 & 安全(非常重要)

方式 A:直接暴露(不推荐)

sudo ufw allow 5901

方式 B:SSH 隧道(推荐 ✅)

不要直接开放 5901 端口

在本地电脑执行:

ssh -L 5901:localhost:5901 user@ubuntu_ip

三、客户端连接

Windows / macOS

使用:

  • RealVNC Viewer
  • TigerVNC
  • TightVNC

连接地址:

localhost:5901   (使用SSH隧道)
或
ubuntu_ip:5901   (直接暴露)

四、设置开机自启(可选)

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

示例:

[Unit]
Description=VNC Server
After=network.target

[Service]
Type=forking
User=youruser
ExecStart=/usr/bin/vncserver :1
ExecStop=/usr/bin/vncserver -kill :1

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1

五、常见问题

❌ 灰屏 / 黑屏

  • xstartup 没写对
  • 没装桌面环境

❌ 连接被拒绝

  • VNC 没启动
  • 端口不对
  • 防火墙拦截

✅ 更安全的替代方案

  • xrdp(Windows 远程桌面)
  • NoMachine
  • RustDesk

如果你告诉我:

  • Ubuntu 版本
  • 是否有公网 IP
  • 用 Windows / macOS / Linux 连接

我可以给你更精确的配置方案。

0 踩