跳至主要內容

GNOME图形化界面安装使用

zhengcog...大约 4 分钟Linux

本文在centos7.9下操作

图形化界面安装

本文安装GNOME Desktop和X Window System

安装 GNOME Desktop

yum groupinstall -y "GNOME Desktop"

安装X Window System

yum groupinstall "X Window System"

启动桌面环境

  1. 一次性的,在终端里输入startx;
  2. 系统启动时默认进入桌面环境: systemctl set-default graphical.target,然后重启

查看当前启动方式常用命令:

# 查看当前默认启动方式
systemctl get-default

# 查看启动可选tag
cat /etc/inittab

# 修改默认启动方式为图形化界面
systemctl set-default graphical.target

远程桌面连接服务安装和使用

远程桌面技术有多种,例如VNC, TeamViewer, RDP等,本文使用免费且广泛使用的VNC。

安装vnc-server

在服务器上先安装服务端(tigervnc是tightvnc的分支):

yum install -y tigervnc-server

配置vnc-server

复制一份vnc配置

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:10001.service

提示

上述命令参数中的"@:10001",可以将数字1换成30000内的任意数字,"5900+数字"即为程序的显示(监听)端口,如"@:10001"表示监听15901端口。

编辑该配置文件,将文件内的<USER>替换成远程连接时的登录用户名(如果是root,注意将第二个<USER>所在行的"/home"移除掉)。

以root身份的配置示例:

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Replace <USER> with the actual user name and edit vncserver
#    parameters in the wrapper script located in /usr/bin/vncserver_wrapper
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.


[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper root %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

设置vnc连接密码

vncpasswd

# 输入两次密码相同即可

提示

vnc连接密码与登录密码不同,vnc连接密码用于远程桌面连接,登录密码用于用户登录系统

设置好后,启动vnc服务:

systemctl daemon-reload
systemctl start vncserver@:10001
systemctl enable vncserver@:10001

以普通用户admin身份配置实例:

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Replace <USER> with the actual user name and edit vncserver
#    parameters in the wrapper script located in /usr/bin/vncserver_wrapper
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.


[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper admin %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

新增用户admin,密码为:admin

useradd -d /home/admin -m -s /bin/bash admin

# 设置密码
passwd admin

启动服务vnc服务:

#切换到admin用户
su admin
#设置vnc密码,输入两次密码即可
vncpasswd
# 退出admin用户,切换回root用户
exit
# 启动服务
systemctl daemon-reload
systemctl start vncserver@:10001
systemctl enable vncserver@:10001

提示

如果开启了防火墙,需放行相应的端口

使用客户端连接vnc

mac上可以使用:

  • Remote Desktop – VNC,输入vnc://ip:port,再输入vnc连接密码即可
  • 直接使用仿达->前往->连接服务器
上次编辑于:
贡献者: Hyman
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.5