服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Centos - Centos7远程桌面 vnc/vnc-server的设置详解

Centos7远程桌面 vnc/vnc-server的设置详解

2021-11-19 17:19CentOS教程网 Centos

这篇文章主要介绍了Centos7远程桌面 vnc/vnc-server的设置详解的相关资料,需要的朋友可以参考下

Centos7与Centos6.x有了很大的不同。

为了给一台服务器装上远程桌面,走了不少弯路。写这篇博文,纯粹为了记录,以后如果遇到相同问题,可以追溯。

1、假定你的系统没有安装vnc的任何软件,那么,首先安装vnc

yum -y install tigervnc-server tigervnc

2、Centos7之前的系统,如果安装vnc一般都需要配置

?
1
2
[root@localhost ~]# cat /etc/sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service

但是,如上所述,Centos7需要配置的文件在

?
1
2
[root@localhost ~]# ll /lib/systemd/system/vncserver@.service
-rw-r--r--. 1 root root 1744 Jun 10 14:15 /lib/systemd/system/vncserver@.service

3、文件内有如下提示

?
1
2
3
4
5
6
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
# 2. Edit <USER> and vncserver parameters appropriately
#  ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service

4、复制一份文件,并改名为vncserver@:1.service

[root@localhost ~]# cp /lib/systemd/system/vncserver@.service/lib/systemd/system/vncserver@:1.service

5、将文件中的<User>用你当前的用户替换,将%i替换为1

?
1
2
3
4
5
6
7
8
9
10
11
12
[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 :1 > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver :1 -geometry 1280x720 -depth 24"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target

6、更新systemctl

systemctl daemon-reload

7、设置为自动启动

systemctl enable vncserver@:1.service

8、启动vnc服务

systemctl start vncserver@:1.service

9、在iptables中加入对应的端口5901(注意,如果有其他用户,那么也需要将端口加上。vnc的端口默认是5900 + n)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost system]# cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

注意:

1、如果你不配置和启用防火墙,此时用VNC Viewer连接的话,会报:"connect:Connection timed out(10060)"错误。

2、本文是以root用户为例,如果其他用户也需要登录,那么,还需要将文件复制为

cp /lib/systemd/system/vncserver@.service/lib/systemd/system/vncserver@:2.service

同时,将文件内的%i改为2,并建立对应用户的vncpasswd。

3、你可以通过UltraVNC,TigerVNC或者RealVNC Viewer进行访问,我在win7下使用这3中工具均能连接

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

延伸 · 阅读

精彩推荐
  • CentosCentOS7 阿里云的yum源使用详解

    CentOS7 阿里云的yum源使用详解

    这篇文章主要介绍了CentOS7 阿里云的yum源使用详解的相关资料,这里对备份yum源,添加EPEL源,和缓存清理,进行了介绍,需要的朋友可以参考下...

    天王9312020-12-28
  • Centos在CentOS系统上安装Docker的教程

    在CentOS系统上安装Docker的教程

    这篇文章主要介绍了在CentOS系统上安装Docker的教程,Docker是当下人气最为火热的容器类虚拟软件,需要的朋友可以参考下 ...

    开源中文社区3952019-09-17
  • Centos使用Xshell连接Centos 6.6服务器操作图文教程

    使用Xshell连接Centos 6.6服务器操作图文教程

    这篇文章主要介绍了使用Xshell连接Centos 6.6服务器操作图文教程,本文用详细的操作步骤讲解了如何使用Xshell连接Centos服务器,需要的朋友可以参考下 ...

    脚本之家4032019-09-18
  • CentosCentOS上SVN服务器端程序的安装与使用教程

    CentOS上SVN服务器端程序的安装与使用教程

    SVN是一款高人气的软件项目版本控制系统,由于其在Windows的客户端的简易操作,在Git的浪潮中仍然保有很多的用户数量,这里我们就来看一下CentOS上SVN服务器端...

    cnblogs3902019-07-16
  • CentosCentOS 最新版本git的安装教程

    CentOS 最新版本git的安装教程

    本文主要给大家介绍了CentOS 最新版本git的安装教程,非常不错,具有参考借鉴价值,感兴趣的朋友一起看看吧...

    CentOS教程网9252021-11-29
  • CentosCentOS系统下软件包的制作方法和过程详解

    CentOS系统下软件包的制作方法和过程详解

    今天小编将为大家带来的是CentOS系统下软件包的制作方法和过程详解;希望对大家会有帮助,有需要的朋友一起去看看吧...

    CentOS之家4802019-05-30
  • Centoscentos 7中添加一个新用户并授权的步骤详解

    centos 7中添加一个新用户并授权的步骤详解

    这篇文章主要给大家介绍了关于在centos 7中添加一个新用户并授权的步骤,文中将实现的步骤介绍的非常详细,通过文中介绍的步骤可以轻松的创建一个新...

    Ryan.Miao9832022-02-12
  • CentosCentOS6.2网卡设置

    CentOS6.2网卡设置

    如果你想让服务器可以更新、让网友访问你的LINUX服务器,那一定要设置LINUX网上给网卡绑定一个IP,下面我们就介绍CentOS6.2网卡设置IP的方法。...

    CentOS教程网10092021-10-03