Configuration and use of VNCServer in CentOS

Source: Internet
Author: User
VNC is an excellent remote control tool software developed by the famous AT & amp; T European research laboratory. VNC is based on UNIX and

VNC is an excellent remote control tool software developed by the famous AT&T European research laboratory. VNC is a free open-source software based on UNIX and Linux operating systems. it has powerful remote control capabilities and is highly efficient and practical. its performance can be comparable to any remote control software in Windows and MAC. In Linux, VNC includes the following commands: vncserver, vncviewer, vncpasswd, and vncconnect. In most cases, you only need two commands: vncserver and vncviewer.

1. Command description

Vncserver: This service program must run on the master (or remote control) computer. You can only use this service as a user (without the root user identity.
Vncviewer: a local application used to remotely access a computer running vncserver and display its environment. You need to know the IP address of the remote computer and the password set by the vncserver.
Vncpasswd: Password setting tool for vncserver. The vncserver service program cannot run without a password (good habit ). If you have not set the password, it will prompt you to enter a password when running vncserver. Therefore, I usually do not run this command to set the password.
Vncconnect: Tells the vncserver to connect to the IP address and port number of a remote computer running vncviewer. In this way, I can avoid giving others a password for access.
Xvnc: a "master" program of vnc, which generally does not need to be run directly. (Vncserver and vncviewer are Xvnc scripts)
Find all available options and run:
Xvnc -- help
For security reasons, it is generally not recommended to run the vncserver program directly with a super user account. If you need a super user environment, log on to the Super User account using the su command.
The workflow for running VNC is as follows:
(1) connect the VNC client to the VNC Server through a browser or VNC Viewer.
(2) The VNC Server sends a dialog window to the client, requiring that you enter the connection password and access the VNC Server display device.
(3) after the client enters the online password, the VNC Server verifies that the client has access permissions.
(4) if the client passes the VNC Server verification, the client requires the VNC Server to display the desktop environment.
(5) The VNC Server uses X Protocol to require X Server to assign control of the display to the VNC Server.
(6) The VNC Server will be sent to the client using the VNC communication protocol in the desktop environment of X Server in the future, and allow the client to control the desktop environment and input device of the VNC Server.

The following installation environment is CentOS6.5.

2. install VNC

First, check whether VNC is installed on the local machine. by default, CentOS 6.0 is not installed.
Check for installation. enter:

[Plain] view plaincopyprint? 01. [root @ localhost ~] # Rpm-q vnc-server
[Root @ localhost ~] # Rpm-q vnc-server:

[Plain] view plaincopyprint? 01. package vnc is not installed
02. package vnc-server is not installed
Package vnc is not installed
Package vnc-server is not installed
If the prompt is not installed, start the installation. enter:

[Plain] view plaincopyprint? 01. [root @ localhost ~] # Yum install vnc-server
[Root @ localhost ~] # Yum install vnc-server note: If it is Ubuntu, enter:

[Plain] view plaincopyprint? 01. [root @ localhost ~] # Apt-get install vnc-server
[Root @ localhost ~] # Apt-get install vnc-server system will prompt you to confirm some options, enter "Y" to confirm.

Set VNC password for the first time

[Plain] view plaincopyprint? 01. [root @ localhost ~] # Vncserver
[Root @ localhost ~] # Vncserver
Repeat the input twice.

3. configure the desktop

[Plain] view plaincopyprint? 01. [root @ localhost ~] # Vi ~ /. Vnc/xstartup
[Root @ localhost ~] # Vi ~ /. Vnc/xstartup mainly modifies the last two rows. Changed:

[Plain] view plaincopyprint? 01. # xterm-geometry 80x24 + 10 + 10-ls-title "$ VNCDESKTOP Desktop "&
02. # twm &
03. gnome-session &
# Xterm-geometry 80x24 + 10 + 10-ls-title "$ VNCDESKTOP Desktop "&
# Twm &
Gnome-session & usually comment out the last two lines of the original configuration file and add a line of code, indicating that the "Gnome" desktop is used.

Save the file.

4. configure the logon account

[Root @ localhost ~] # Vi/etc/sysconfig/vncservers

The following prompt is displayed:

# The VNCSERVERS variable is a list of display: user pairs.

[Plain] view plaincopyprint? 01 .#
02. # Uncomment the lines below to start a VNC server on display: 2
03. # as my 'myusername' (adjust this to your own). You will also
04. # need to set a VNC password; run 'Man vncpasswd' to see how
05. # to do that.
06 .#
07. # do not run this service if your local area network is
08. # untrusted! For a secure way of using VNC, see this URL:
09. # http://kbase.redhat.com/faq/docs/DOC-7028
10. # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
11. # Use "-localhost" to prevent remote VNC clients connecting failed t when
12. # doing so through a secure tunnel. See the "-via" option in
13. # 'Man vncviewer 'manual page.
14.
15.
16. # VNCSERVERS = "2: myusername"
17. # VNCSERVERARGS [2] = "-geometry 800x600-nolisten tcp-localhost"
#
# Uncomment the lines below to start a VNC server on display: 2
# As my 'myusername' (adjust this to your own). You will also
# Need to set a VNC password; run 'Man vncpasswd' to see how
# To do that.
#
# Do not run this service if your local area network is
# Untrusted! For a secure way of using VNC, see this URL:
# Http://kbase.redhat.com/faq/docs/DOC-7028
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-localhost" to prevent remote VNC clients connecting tables T when
# Doing so through a secure tunnel. See the "-via" option in
# 'Man vncviewer 'manual page.
# VNCSERVERS = "2: myusername"
# VNCSERVERARGS [2] = "-geometry 800x600-nolisten tcp-localhost"
Edit the last two lines and remove the comments of the two lines:

[Plain] view plaincopyprint? 01. VNCSERVERS = "1: root"
02. VNCSERVERARGS [1] = "-geometry 1024x768"
VNCSERVERS = "1: root"
VNCSERVERARGS [1] = "-geometry 1024x768"
If you have multiple accounts, configure them in the following format.

[Plain] view plaincopyprint? 01. VNCSERVERS = "1: user1 2: user2 3: user3"
02. VNCSERVERARGS [1] = "-geometry 1024 × 768"
03. VNCSERVERARGS [2] = "-geometry 1024 × 768"
04. VNCSERVERARGS [3] = "-geometry 800 × 600-depth 24-nolisten tcp-nohttpd-localhost" # tcp is not supported, http connections are not supported, and access can only be tested locally.
VNCSERVERS = "1: user1 2: user2 3: user3"
VNCSERVERARGS [1] = "-geometry 1024 × 768"
VNCSERVERARGS [2] = "-geometry 1024 × 768"
VNCSERVERARGS [3] = "-geometry 800 × 600-depth 24-nolisten tcp-nohttpd-localhost" # tcp is not supported, http connections are not supported, and access can only be tested locally.
If user2 is used, perform the following operations on user2:

[Plain] view plaincopyprint? 01. [root @Localhost~] # Su user2
02. [test @Localhost~] $ Mkdir. vnc // * Create A. vnc directory to save this user's vnc configuration file *//
03. [test @Localhost~] $ Vncpasswd // * Set the vnc Remote connection password of user2 *//
04. [test @Localhost~] $ Su root
05. [root @Localhost~] # Service vncserver restart
[Root @ localhost ~] # Su user2
[Test @ localhost ~] $ Mkdir. vnc // * Create A. vnc directory to save this user's vnc configuration file *//
[Test @ localhost ~] $ Vncpasswd // * Set the vnc Remote connection password of user2 *//
[Test @ localhost ~] $ Su root
[Root @ localhost ~] # Service vncserver restart

5. configure the firewall and System Services

The VNC server listening port starts from 5900. The display: 1 listening port is 5901, the display: 2 listening port is 5902, and so on. By default, the CentOS firewall does not allow connection to these ports. Therefore, use the following steps to open the firewall:

[Plain] view plaincopyprint? 01. [root @ localhost ~] # Vi/etc/sysconfig/iptables
[Root @ localhost ~] # In vi/etc/sysconfig/iptables, only one root account and desktop 1 are added. Therefore, add a "5901" port number according to the above rules.

[Plain] view plaincopyprint? 01.-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 5901-j ACCEPT restart the firewall service.
Set VNC to start automatically

[Plain] view plaincopyprint? 01. [root @ localhost ~] # Chkconfig-level 345 vncserver on
[Root @ localhost ~] # Chkconfig-level 345 vncserver on

6. test the VNC connection

Take windows vncviewer connection as an example:
 

Enter password

Expected results

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.