在 Debian 上实现 VNC 远程访问,通常分为 安装 VNC Server → 配置 → 设置访问方式 → 客户端连接 四个步骤。下面给你一份 常用、稳定、适合新手 的做法(以 Debian 11/12 为例)。
VNC 需要有桌面环境。
sudo apt update
sudo apt install -y task-gnome-desktop
或(更轻量):
sudo apt install -y xfce4 xfce4-goodies
sudo apt install -y tigervnc-standalone-server tigervnc-common
su - youruser
vncpasswd
密码用于 VNC 连接(不是系统密码)。
mkdir -p ~/.vnc
nano ~/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
如果是 GNOME:
exec gnome-session
chmod +x ~/.vnc/xstartup
vncserver :1 -geometry 1920x1080 -depth 24
说明:
:1 → 端口 5901:2 → 5902查看端口:
ss -lntp | grep 59
sudo nano /etc/systemd/system/vncserver@.service
内容(替换 youruser):
[Unit]
Description=VNC Server (%i)
After=network.target
[Service]
Type=forking
User=youruser
PAMName=login
ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -depth 24
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1
sudo systemctl start vncserver@1
sudo ufw allow 5901/tcp
使用以下客户端:
连接地址:
Debian_IP:5901
示例:
192.168.1.100:5901
使用 SSH 隧道:
ssh -L 5901:localhost:5901 user@debian_ip
客户端连接:
localhost:5901
vncpasswd
xstartup 未执行| 需求 | 推荐 |
|---|---|
| 云服务器 | XRDP(3389) |
| 高安全 | VNC + SSH |
| 多用户 | TigerVNC + systemd user |
| Wayland | 暂不支持 VNC |
如果你愿意,可以告诉我:
我可以给你 完全定制的一套配置方案。