Linux系统安装和配置 VNC 服务器

文章目录

    • [1.安装 GNOME 桌面环境](#1.安装 GNOME 桌面环境)
    • [2.安装 VNC 服务器(tigervnc-server)](#2.安装 VNC 服务器(tigervnc-server))
    • [3.为本地用户设置 VNC 密码](#3.为本地用户设置 VNC 密码)
    • [4.设置 VNC 服务器配置文件](#4.设置 VNC 服务器配置文件)
    • [5.启动 VNC 服务并允许防火墙中的端口](#5.启动 VNC 服务并允许防火墙中的端口)

1.安装 GNOME 桌面环境

shell 复制代码
[root@server6 ~]# dnf groupinstall "workstation" -y

成功安装上面的包后,请运行以下命令启用图形模式

[root@server6 ~]# systemctl set-default graphical

重启一下系统

shell 复制代码
[root@server6 ~]# reboot

重启后,取消注释 /etc/gdm/custom.conf文件 中的 WaylandEnable=false,以使通过 vnc 进行的远程桌面会话请求由 GNOME 桌面的 xorg 处理,来代替 Wayland 显示管理器

shell 复制代码
[root@server6 ~]# vim /etc/gdm/custom.conf

2.安装 VNC 服务器(tigervnc-server)

shell 复制代码
[root@server6 ~]# dnf install tigervnc-server tigervnc-server-module -y

3.为本地用户设置 VNC 密码

shell 复制代码
[root@server6 ~]# vncpasswd

4.设置 VNC 服务器配置文件

shell 复制代码
/etc/systemd/system/vncserver@.service
shell 复制代码
[root@linuxtechi ~]# vim /etc/systemd/system/vncserver@.service
[Unit]
Description=Remote Desktop VNC Service
After=syslog.target network.target

[Service]
Type=forking
WorkingDirectory=/home/pkumar
User=pkumar
Group=pkumar

ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -autokill %i
ExecStop=/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target

5.启动 VNC 服务并允许防火墙中的端口

shell 复制代码
[root@server6 ~]# systemctl daemon-reload
[root@server6 ~]# systemctl start vncserver@:1.service
[root@server6 ~]# systemctl enable vncserver@:1.service
Created symlink /etc/systemd/system/multi-user.target.wants/vncserver@:1.service → /etc/systemd/system/vncserver@.service.
[root@server6 ~]# netstat -tunlp | grep 5901
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      56182/Xvnc          
tcp6       0      0 :::5901                 :::*                    LISTEN      56182/Xvnc          
[root@server6 ~]# ss -tunlp | grep -i 5901
tcp   LISTEN 0      5             0.0.0.0:5901       0.0.0.0:*    users:(("Xvnc",pid=56182,fd=6))                          
tcp   LISTEN 0      5                [::]:5901          [::]:*    users:(("Xvnc",pid=56182,fd=7))                          

使用下面的 systemctl 命令验证 VNC 服务器的状态

shell 复制代码
[root@server6 ~]# systemctl status vncserver@:1.service
相关推荐
你想考研啊2 小时前
四、jenkins自动构建和设置邮箱
运维·jenkins
Code blocks2 小时前
使用Jenkins完成springboot项目快速更新
java·运维·spring boot·后端·jenkins
snoopyfly~2 小时前
Ubuntu 24.04 LTS 服务器配置:安装 JDK、Nginx、Redis。
java·服务器·ubuntu
独行soc2 小时前
#渗透测试#批量漏洞挖掘#HSC Mailinspector 任意文件读取漏洞(CVE-2024-34470)
linux·科技·安全·网络安全·面试·渗透测试
BD_Marathon2 小时前
Ubuntu下Tomcat的配置
linux·ubuntu·tomcat
饥饿的半导体3 小时前
Linux快速入门
linux·运维
BD_Marathon3 小时前
Ubuntu:Tomcat里面的catalina.sh
linux·ubuntu·tomcat
BD_Marathon3 小时前
设置LInux环境变量的方法和区别_Ubuntu/Centos
linux·ubuntu·centos
Me4神秘3 小时前
Linux国产与国外进度对垒
linux·服务器·安全
zhaowangji3 小时前
ubuntu 20.04 安装中文输入法 (sougou pin yin)
linux·ubuntu