centos7安装vnc远程桌面
程序员文章站
2024-01-02 17:32:28
一:安装GNOME Desktop图形桌面服务二:安装VNC三:修改系统运行状态,启动桌面模式四:设置vnc用systemctl来管理(第一个用户vncserver@:1.service,第二个用户vncserver@:2.service,其他以此类推)五:修改VNC用户root(其他系统用户也可以这样改)六:启动,关闭,重启,查看VNC命令七:下载VNC客户端一:安装GNOME Desktop图形桌面服务### 关闭防火墙[root@localhost ~]# s......
四:设置vnc用systemctl来管理(第一个用户vncserver@:1.service,第二个用户vncserver@:2.service,其他以此类推)
一:安装GNOME Desktop图形桌面服务
### 关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# yum groupinstall "GNOME Desktop" -y
执行上面命令可能会报错
解决方案
[root@localhost ~]# yum update grub2-common
[root@localhost ~]# rpm -q grub2-common
grub2-common-2.02-0.81.el7.centos.noarch
[root@localhost ~]# yum install fwupdate-efi
二:安装VNC
[root@localhost ~]# yum install tigervnc-server
三:修改系统运行状态,启动桌面模式
systemctl set-default graphical.target由命令行模式更改为图形界面模式
systemctl set-default multi-user.target由图形界面模式更改为命令行模式
[root@localhost ~]# systemctl get-default
[root@localhost ~]# systemctl set-default graphical.target
[root@localhost ~]# init 5
[root@localhost ~]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
四:设置vnc用systemctl来管理(第一个用户vncserver@:1.service,第二个用户vncserver@:2.service,其他以此类推)
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
五:修改VNC用户root(其他系统用户也可以这样改)
[root@localhost ~]# cat /etc/systemd/system/vncserver@:1.service
# 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=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
### 刷新systemctl
[root@localhost ~]# systemctl daemon-reload
### 设置vnc密码(第二个用户修改密码,vncpasswd user2,其他以此类推)
[root@localhost ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
[root@localhost ~]# cat /etc/sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768 -BlacklistTimeout 0"
六:启动,关闭,重启,查看VNC命令
### 启动
[root@localhost ~]# systemctl start vncserver@:1.service
### 停止
[root@localhost ~]# systemctl stop vncserver@:1.service
### 重启
[root@localhost ~]# systemctl restart vncserver@:1.service
### 查看状态
[root@localhost ~]# systemctl status vncserver@:1.service
七:下载VNC客户端
一直点点点就好,安装好之后win+s搜索vnc
输入账号密码,连接成功
本文地址:https://blog.csdn.net/tiger199/article/details/107345105