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/[email protected]
shell 复制代码
[root@linuxtechi ~]# vim /etc/systemd/system/[email protected]
[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/[email protected].
[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
相关推荐
珊珊而川23 分钟前
ChatPromptTemplate创建方式比较
服务器·langchain
欧先生^_^2 小时前
Linux内核可配置的参数
linux·服务器·数据库
若风的雨2 小时前
【deekseek】P2P通信路由过程
服务器·网络协议·p2p
海尔辛2 小时前
学习黑客5 分钟读懂Linux Permissions 101
linux·学习·安全
Python私教2 小时前
征服Rust:从零到独立开发的实战进阶
服务器·开发语言·rust
王RuaRua3 小时前
[数据结构]5. 栈-Stack
linux·数据结构·数据库·链表
曼岛_4 小时前
[架构之美]linux常见故障问题解决方案(十九)
linux·运维·架构
tan180°4 小时前
Linux进程信号处理(26)
linux·c++·vscode·后端·信号处理
大神的风范4 小时前
从0开始学linux韦东山教程第三章问题小结(4)
linux·服务器
sz66cm4 小时前
Linux基础 -- SSH 流式烧录与压缩传输笔记
linux·笔记·ssh