温馨提示×

怎样配置debian的tigervnc

小樊
49
2026-09-08 15:17:31
栏目: 智能运维

下面以 Debian 11/12 为例,介绍如何安装和配置 TigerVNC(服务端 + 客户端基本用法)。


一、安装 TigerVNC

sudo apt update
sudo apt install tigervnc-standalone-server tigervnc-common

(可选)如果希望使用图形界面登录管理器:

sudo apt install tigervnc-xorg-extension

二、为当前用户配置 VNC 密码

vncpasswd

密码会保存在:

~/.vnc/passwd

三、创建 VNC 启动脚本

编辑 ~/.vnc/xstartup:

nano ~/.vnc/xstartup

示例(使用 Xfce,轻量稳定):

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4

如果是 GNOME:

#!/bin/sh
exec /etc/X11/Xsession

赋予执行权限:

chmod +x ~/.vnc/xstartup

四、启动 TigerVNC 服务

1️⃣ 手动启动(端口 5901 = :1)

vncserver :1 -geometry 1280x720 -depth 24

停止:

vncserver -kill :1

五、配置 systemd(推荐,开机自启)

1️⃣ 复制模板

sudo cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

2️⃣ 修改配置

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

修改 User 和 HOME:

[Service]
User=youruser
Group=youruser
WorkingDirectory=/home/youruser
PIDFile=/home/youruser/.vnc/%H%i.pid
ExecStartPre=/usr/bin/vncserver -kill :1
ExecStart=/usr/bin/vncserver :1 -geometry 1280x720 -depth 24
ExecStop=/usr/bin/vncserver -kill :1

3️⃣ 启用服务

sudo systemctl daemon-reload
sudo systemctl enable --now vncserver@:1

查看状态:

systemctl status vncserver@:1

六、防火墙(如有)

sudo ufw allow 5901/tcp

⚠️ 建议通过 SSH 隧道访问,不要直接暴露 5901 到公网


七、客户端连接

Linux / Windows

使用 TigerVNC Viewer:

localhost:5901

SSH 隧道(推荐)

ssh -L 5901:localhost:5901 user@server_ip

然后连接:

localhost:5901

八、常见问题

❌ 黑屏

  • 检查 .vnc/xstartup 是否可执行
  • 桌面环境是否安装(xfce4 / gnome)

❌ 无法启动

rm -rf /tmp/.X11-unix/*

如果你告诉我:

  • Debian 版本
  • 使用的桌面环境(GNOME / Xfce / KDE)
  • 是否要 多用户 / 开机自启 / 加密

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

0 踩