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
相关推荐
weixin_471525783 小时前
【gdb/sqlite3移植/mqtt】
linux·运维·服务器
大聪明-PLUS3 小时前
TCP/IP 协议族—理论与实践(一)
linux·嵌入式·arm·smarc
迎風吹頭髮6 小时前
Linux内核架构浅谈2- Linux内核与硬件交互的底层逻辑:硬件抽象层的作用
linux·架构·交互
Guheyunyi7 小时前
消防管理系统如何重构现代空间防御体系
大数据·运维·人工智能·安全·信息可视化·重构
我是好小孩7 小时前
【Android】六大设计原则
android·java·运维·服务器·设计模式
孙同学要努力7 小时前
《Linux篇》进程状态——浅度、深度睡眠状态、僵尸状态、运行状态
linux·运维
jieyu11198 小时前
Linux Rootkit 详解
linux·运维·系统安全
宁檬精8 小时前
运维面试准备——综合篇(一)
linux·运维·服务器
洛阳纸贵Coco.Leo.YI8 小时前
10分钟在Windows11下Ubuntu内安装docker-Version28.51
linux·ubuntu·docker
阿巴~阿巴~8 小时前
Ubuntu 20.04 安装 Redis
linux·服务器·数据库·redis·ubuntu