Install VNC Server on CentOS / RedHat 5 / 6
rpm -i vnc-server-4.1.2-14.el5_6.6.x86_64.rpm
# 默认的 VNC server 启动脚本用 xterm 启动 X Server,但是默认的 CentOS / RedHat 里没有 xterm
echo "exec gnome-session &" >> ~/.vnc/xstartup
vncserver # set password the first time
设置 vncserver 自启动 (有时安装 vncserver 后需要重启一次才能被 chkconfig 识别?)
chkconfig vncserver on
/etc/init.d/vncserver start
Config
/etc/sysconfig/vncservers
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 800x600 -alwaysshared -depth 24"
Install VNC Server on CentOS / RedHat 7
yum install vnc-server # will install tigervnc-server
vncpasswd
# will create /etc/systemd/system/multi-user.target.wants/vncserver@:1.service
systemctl enable --now vncserver@:1echo 'session=gnome' > ~/.vnc/config
Install vnc server on RHEL 8
参考文档。有修改使适用于 root 用户直接 VNC 登录。以下所有命令 root 用户身份执行。
首先关闭防火墙(如果还没有的话):
systemctl disable --now firewalld
安装和配置 VNC 服务:
yum install tigervnc-server tigervnc
yum group install GNOME base-x
yum groupinstall "Server with GUI"
# Set the system to boot directly into the GUI then switch to graphical.target:
systemctl set-default graphical.target
systemctl isolate graphical.target
vncpasswd # 根据提示设置 VNC 的密码
echo 'session=gnome' > ~/.vnc/config
echo ':1=root' >> /etc/tigervnc/vncserver.users
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
systemctl enable --now vncserver@:1.service
确认 VNC 服务状态:
systemctl status vncserver@:1.service
ss -atp | grep 5901
# 重启 VNC 服务
systemctl restart vncserver@:1.service
Tips & Solutions
VNC 安全性
参考Wiki。大部分 VNC server 没有对传输内容加密( credentials 是加密的)。要保证安全性,建议通过 ssh tunnel 使用 VNC。
作为对比,rdp 在 win 7 之后默认强制启用 Network Level Authentication (NLA, 网络级别身份验证),其本质上是 TLS,所有传输内容都是加密的(首次连接服务器时 rdp client 会提示接收服务器的证书)。
GNOME session timeout
# Timeout for blanking the screen (seconds; 0 = never):
gsettings set org.gnome.desktop.session idle-delay 0
#Timeout for locking the screen after blanking (seconds; 0 = instant):
gsettings set org.gnome.desktop.screensaver lock-delay 0
以上命令可能需要在 VNC 窗口的 GNOME terminal 应用里执行才有效。通过 ssh 执行报错 "failed to commit changes to dconf: Could not connect: No such file or directory"。
Use VNC Client
VNC Server 默认运行在 (udp) 5901 端口。(第二个启动的 VNC Server 实例则是 5902 端口,以此类推)
使用 VNC Client 连接时,使用 IP:PORT 格式的地址连接服务器,一些 VNC Client 不能省略默认端口。如果 PORT 部分设为 1,某些 VPC Client 会将其视为 "display number",而将这个值 + 5900 后作为实际使用的端口。