How to share Remote Desktop with VNC

Source: Internet
Author: User

VNC, all called Virtual Network Computing, is a desktop sharing system. It is similar to the Remote Desktop function in windows. VNC uses the RFB (Remote FrameBuffer, Remote frame buffer) Protocol to remotely control another computer. It sends keyboard and mouse actions to the remote computer and sends the screen of the remote computer back to the local computer.
VNC technology has nothing to do with the platform. VNC Viewer can be on a different operating system than VNC Server. VNC supports almost all operating systems, Java, and even Java browsers to access the VNC Server. Multiple VNC clients can connect to a VNC Server at the same time.

VNC was initially developed by AT&T and its source code is open source.

It is easy to configure the VNC service on CentOs 4.3 (assuming that VNC software has been installed on your computer)

First, you need to configure the VNC password, which is used when connecting to the server using the client.

Note: The VNC password is saved in the user's home directory. You can set your own password for each user. Therefore, use your user name (do not use root as much as possible) to run the following command:

Vncpasswd

Enter the password.

Then you can start the VNC server. When starting the VNC server, you must specify a display parameter for your server. You can regard display as a desktop, and every user can have their own desktop. When connecting to a VNC client, you can specify which desktop to connect. In the system, the display number cannot be repeated. That is to say, if a user has created a display named ": 1", another user cannot use ": 1, it can use ": 2 ".

The command to start the VNC server is:

Vncserver <display>

For example,

Vncserver: 1

Finally, you need to configure the firewall to allow the VNC client to connect to the VNC server. 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, you need to use the following steps to open the firewall (root permission required ):

Vi/etc/sysconfig/iptables

Find the following statement:

-A RH-Firewall-1-INPUT-j REJECT -- reject-with icmp-host-prohibited

Add the following content before this line:

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 5900: 5903-j ACCEPT

The meaning of this statement is to allow other machines to access ports 5900 to 5903 of the local machine. In this way, users of display: 1, display: 2, display: 3 can connect to the local machine.

Then use the root identity to restart the Firewall:

/Sbin/service iptables restart

Now you can run the client software and connect it to the VNC server.

There are many VNC client software. In linux, there is vncviewer. KDE also provides a krdc (its menu item is "Remote Desktop Connection" and Remote Desktop Connection ).

There are also many vnc clients in window. You can download them at http://www.realvnc.com/and install them.

Suppose that the IP address of the VNC server is 192.168.1.1, and the display is: 1. Enter "192.168.1.1: 1" in the server column of the VNC viewer and connect to the VNC viewer. OK. You can see your desktop. In the future, no matter when you shut down your local PC, as long as the server is not shut down, you only need to connect to the VNC server, you can see that the desktop remains unchanged when you shut down the local PC the day before.
But ...... Why is this desktop so ugly ?!

The default window manager used by vncserver is twm, which is a simple window manager. You can change your desktop to GNOME or KDE.

You can go to your home directory and edit the file:. vnc/xstartup. The content of this file is as follows:

#! /Bin/sh

# Uncomment the following two lines for normal desktop:

# Unset SESSION_MANAGER

# Exec/etc/X11/xinit/xinitrc

[-X/etc/vnc/xstartup] & exec/etc/vnc/xstartup

[-R $ HOME/. Xresources] & xrdb $ HOME/. Xresources

Xsetroot-solid gray

Vncconfig-iconic &

Xterm-geometry 80x24 + 10 + 10-ls-title "$ VNCDESKTOP Desktop "&

# Twm &

Gnome-session &

You can comment out the line "twm &" as above, and then add a line "gnome-session &", or "startkde &", start GNOME desktop and KDE Desktop respectively.

If the server restarts, you need to run the vncserver command again to start the VNC server, which is very troublesome. Is there a better way?

Yes! We can start the VNC server as a background service. Perform the following steps:

First, you must allow the VNC server to be started during system startup. You can use the "System Settings> Server Settings> Services" menu to configure the vncserver.

If you use the command line, run the following two commands as root:

Cd/etc/rc5.d

Mv K35vncserver S35vncserver

Edit/etc/sysconfig/vncservers. The following is the file content:

# The VNCSERVERS variable is a list of display: user pairs.
#
# Uncomment the line below to start a VNC server on display: 1
# 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
# URL: http://www.uk.research.att.com/vnc/sshvnc.html>.
VNCSERVERS = "1: user1 2: user2 3: user3"
VNCSERVERARGS [1] = "-geometry 1024x768"
VNCSERVERARGS [2] = "-geometry 1024x768"
VNCSERVERARGS [3] = "-geometry 800x600"


Explain this file:

VNCSERVERS is configured to start several VNC servers when the system starts. In the preceding example, three VNC servers are run, where user1 is displayed: 1, user2 is displayed: 2, user3 is in display: 3.

VNCSERVERARGS sets the startup parameters for VNC server 1, 2, and 3. In the preceding example, the screen resolution is 1024x768 for user1 and user2, and 800x600 for user3.

Use the "man vncserver" command to query other supported parameters.

After editing the file, save it and run it as root:

/Sbin/service vncserver start

In this way, the vncserver of user1, user2, and user3 is started.

After each system restart, the vncserver of these three users will be automatically started.

Note: The above three users must have used the vncpasswd command to set the vnc password, or their vncserver will fail to start!

 

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.