centos 开启VNC

Posted 侠之大者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos 开启VNC相关的知识,希望对你有一定的参考价值。

安装软件包(有yum源安装的,不采用源码安装)

yum -y install vnc vnc-server

安装成功后,配置如下:

[[email protected] ~]# vncserver 
#设置 VNC密码,输入:(在某用户下输入则登陆用户就是它,如果su imiss切换到imiss用户,输入vncserver则启动的是另一个桌面,同样要设置密码,以后在该账户下启动的vncserver登陆就需要在此用户下设置的密码了。)
You will require a password to access your desktops.

Password:
Password must be at least 6 characters - try again
Password:
Verify:
xauth:  creating new authority file /root/.Xauthority

New localhost.localdomain:1 (root) desktop is localhost.localdomain:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log

[[email protected] ~]# vncpasswd 
Password:
Password must be at least 6 characters - try again
Password:
Verify:
[[email protected] ~]# 

修改配置文件:

vim ~/.vnc/xstartup (最后两行)

#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
gnome-session &

vim  /etc/sysconfig/vncservers  (最后两行)

# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
 VNCSERVERS="1:root"
 VNCSERVERARGS[1]="-geometry 800x600"

vi /etc/sysconfig/iptables (配置防火墙)

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5902 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5903 -j ACCEPT
#VNC server 监听的端口从 5900 开始,display:1 的监听 5901,display:2 监听 5902,以此类推。CentOS 的防火墙缺省是不允许连接这些端口的,所以需要使用下面的步骤打开防火墙(需要 root 权限):

 

[[email protected] ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: nat mangle filte[  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

启动服务

[[email protected] ~]# chkconfig vncserver on
[[email protected] ~]# service vncserver start
Starting VNC server: 2:root 
New localhost.localdomain:2 (root) desktop is localhost.localdomain:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log

                                                           [  OK  ]
[[email protected] ~]#

关闭vnc

vncserver -kill :2
#注意kill后面要有一个空格

连接

技术分享

 

以上是关于centos 开启VNC的主要内容,如果未能解决你的问题,请参考以下文章

centos 5.5如何配置vnc,开启linux远程桌面教程

centos6.7 开了20个vnc端口,过2-3天就会出现vnc瘫痪,连接黑屏,有没大神知道原因,求解!

centos7 linux vnc永久开启的方法是啥?每次重启都有vncserver好麻烦

002vnc连接Linux

CentOS 8.1下VNC安装与配置

CentOS 8.1下VNC安装与配置