在Rocky linux8.5下安装vncserver。
1、安装 Gnome 桌面,Gnome桌面包含在“Server with GUI”里面:

dnf groupinstall "Server with GUI" -y

2、安装vncserver:

dnf install tigervnc-server

3、复制文件(将安装的vnc的配置文件复制到运行环境):

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
#这里的数字是启动vnc的端口号,我用的2表示端口号是5902,也就是加上了一个5900

4、修改模板文件,替换其中的[Service】部分:
vim /etc/systemd/system/vncserver@:2.service

[Service]
Type=forking
User=root
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i

5设置vnc密码,这里输入两次密码,然后键入n,表示不启动单独查看用的密码:

vncpasswd

6、启动vncserver:

systemctl start vncserver@:2.service

最后不要忘了在相应的防火墙打开外网对5902端口的访问
7、在客户端启动对服务器的ssh连接,123.123.123.123替换成你服务器的IP

ssh -L 127.0.0.1:5902:127.0.0.1:5902 root@123.123.123.123

8、在客户端启动vncviewer,IP端口设置为:127.0.0.1:5902

启动vncviewer后可以忽略“通过未加密的连接”的提示,因为vncviewer访问的是本地的地址,这之间是未加密的,而数据是通过ssh在服务器和客户端之间传递的,ssh是加密的。

Logo

更多推荐