Ubuntu VNC使用加密传输的常见方法
TightVNC是Ubuntu下常用的轻量级VNC服务器,支持通过SSL/TLS协议加密传输。
sudo apt update && sudo apt install tightvncserver命令安装。sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/vnc/ssl.key -out /etc/vnc/ssl.crt(按提示输入信息,如国家、域名等)。~/.vnc/config文件(若不存在则新建),添加以下内容:SecurityTypes VeNCrypt,TLSVnc,VncAuth 保存后重启TightVNC服务器:tightvncserver -kill :1 && tightvncserver :1(:1表示显示端口5901)。vnc://your_server_ip:5901,并确保客户端勾选“SSL”选项(部分客户端需手动开启)。TigerVNC是功能更强大的VNC实现,支持更完善的SSL加密配置。
sudo apt update && sudo apt install tigervnc-standalone-server tigervnc-common安装。/etc/vnc/ssl.key(私钥)和/etc/vnc/ssl.crt(证书)。~/.vnc/xstartup文件,添加以下内容(替换yourusername为实际用户名):#!/bin/sh exec /usr/bin/tigervncserver -geometry 1920x1080 -depth 24 -localhost no -rfbauth /home/yourusername/.vnc/passwd -rfbport 5900 -ssl -cert /etc/vnc/ssl.crt -key /etc/vnc/ssl.key 保存后赋予执行权限:chmod +x ~/.vnc/xstartup。vncserver :1启动,客户端输入vnc://localhost:5900(通过SSH隧道转发时需调整端口),选择SSL加密选项。SSH隧道是一种无需修改VNC服务器配置的加密方法,通过SSH的加密通道转发VNC流量,适合临时或不想暴露VNC端口的场景。
sudo apt update && sudo apt install openssh-server安装并启动(sudo systemctl start ssh && sudo systemctl enable ssh)。your_username和remote-server为实际值):ssh -L 5901:localhost:5900 your_username@remote-server 此命令将本地的5901端口转发到远程服务器的localhost:5900(VNC默认端口)。localhost:1(对应本地的5901端口),无需额外配置加密选项,SSH会自动处理加密。Stunnel是一款通用的SSL隧道工具,可将非SSL服务(如VNC)包装为SSL加密服务,适合需要统一加密管理的场景。
sudo apt update && sudo apt install tightvncserver stunnel4安装。/etc/ssl/private/vnc.key(私钥)和/etc/ssl/certs/vnc.crt(证书)。/etc/stunnel/stunnel.conf文件,添加以下内容:[vnc] accept = 5900 connect = 127.0.0.1:5900 cert = /etc/ssl/certs/vnc.crt key = /etc/ssl/private/vnc.key verify = 0 其中accept为Stunnel监听的端口(5900),connect为VNC服务器的实际端口(5900)。sudo systemctl start stunnel4 && sudo systemctl enable stunnel4,再启动TightVNC服务器vncserver :1。客户端连接vnc://your_server_ip:5900即可(Stunnel会自动加密)。ufw)允许加密端口(如5900、5901)的流量,命令为sudo ufw allow 5900/tcp。/etc/vnc/config.d/common.custom配置AllowedHosts),仅允许可信IP连接。