A method to realize Remote Desktop sharing with VNC

Source: Internet
Author: User
Tags iptables
VNC, all known as virtual network Computing, is a desktop sharing system. It features similar to Remote Desktop features in Windows. VNC uses the RFB (remote framebuffer-frame buffer) protocol to remotely control another computer. It sends the keyboard, mouse action to the remote computer, and sends the remote computer's screen back to the local.
VNC technology has nothing to do with platforms, and VNC viewer can be on different operating systems with VNC server. VNC supports almost all operating systems and Java, and can even access VNC Server through Java-enabled browsers. Multiple VNC clients can connect to a VNC server at the same time.

VNC was originally developed by At&t, and its source code is open source. Most Linux distributions take a VNC Server release package, as long as you choose to install it.

[Root@localhost ~]# Uname-a

[Root@localhost ~]# rpm-q Vnc-server

1. Configuration of VNC Server

Configure the firewall to allow VNC clients to connect to VNC server. VNC server listens for ports starting at 5900, display:1 listening 5901,display:2 listening for 5902, and so on.

[root@localhost ~] #vi/etc/sysconfig/iptables

Locate the following statement:

-A rh-firewall-1-input-j Reject--reject-with icmp-host-prohibited

Before this trip, add the following:

-A rh-firewall-1-input-m state--state new-m tcp-p tcp--dport 5900:5903-j ACCEPT

The meaning of this sentence is to allow other machines to access the local 5900 to 5903 ports, so that Display:1, Display:2, Display:3 users can connect to the local computer.

Then restart the firewall using the root identity:

[Root@localhost ~]#/sbin/service iptables restart

OK, now you can run the client software and connect to the VNC server.

2. Start VNC Server

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

Note: The VNC password is saved in the user's home directory, and each user can set his or her own password. Therefore, use your username (try not to use root) to run the following command:

[Zhangxh@localhost ~] $vncpasswd

then enter the password.

The VNC server can then be started. When you start VNC server, you need to specify a display parameter for your server, or you can not specify that the server assigns it itself. You can interpret display as a desktop, and each user can have his or her own desktop. When a VNC client connects, it can specify which desktop to connect to. In the system, the display number can not be repeated, that is, if a user has established a ": 1" display, another user can no longer use ": 1", he can use ": 2".

[Zhangxh@localhost ~] $vncserver

PASSWD://If this account is the first time to run Vncserver, you will be asked to enter the password for the connection.
Verify
New ' Server1.linux:4 (demo) ' Desktop is Server1.linux:4
Starting applications specified In/home/demo/.vnc/xstartup
Log file Is/home/demo/.vnc/server1.linux:4.log

The above passage means a graphical terminal, numbered 4, to remember this number, and so on when the login needs to provide this number.
If you want to stop this process, use:

[Zhangxh@localhost ~]$ Vncserver-kill:4

3. Client Connection

VNC client software is many, under Linux has Vncviewer,kde also provides a KRDC (its menu item is "remote Desktop Connection", long-distance desktop Connection).

There are also a lot of VNC clients in Windows, you can go to http://www.realvnc.com/to download one, installation can be used.

Suppose that the IP address of VNC server is 192.168.1.1,display: 1. Enter: "192.168.1.1:1" in the VNC viewer's server bar, and then connect. OK, you can see your desktop now. No matter when you shut down your local PC is not afraid, as long as the server does not shut down, you just connect to VNC server, you can see the day before you shut down the local PC computer desktop is still intact.

4, beautify the interface

Although you can log in at this time, the interface you see after logging in is the X term interface, not the normal X Window interface. Originally vncserver default window manager is TWM, this is a very simple window manager, you can change your desktop to GNOME or KDE. To get into your own home directory and edit the file:. Vnc/xstartup, here's what this file is:

#!/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 Grey

Vncconfig-iconic &

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

#twm &

Gnome-session &

You can comment out the "TWM &" line as above, and then add a line of "Gnome-session &" below, or "Startkde &" to launch the GNOME desktop and KDE desktop respectively.

5, the VNC server into a background service

If the server reboots, you'll need to rerun the Vncserver command to start VNC server, which is cumbersome. There is no better way.

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

First, you allow VNC server to be started during system startup. This can be configured by the "System Setup--> server Settings--> Service" menu to vncserver a selection.

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

Cd/etc/rc5.d

MV K35vncserver S35vncserver

Then edit/etc/sysconfig/vncservers, the following is the file contents:

# 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'll also
# need to set a VNC password; Run ' Mans vncpasswd ' to
# to doing that.
#
# do don't RUN this SERVICE if your the local area network is
# untrusted! For a secure way of using VNC, the
# <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 This line is configured to start several VNC servers at system startup, in the example above running three VNC servers, where User1 in Display:1,user2 Display:2,user3 in Display:3.

Vncserverargs these three lines, VNC server 1, 2, 3 configuration boot parameters, the above example for User1 and user2 using screen resolution 1024x768, to User3 using 800x600.

Other supported parameters please use the "man vncserver" command to query.

After editing this file, save and then run as root:

/sbin/service vncserver Start

So user1, User2, User3 vncserver on the start.

The vncserver of these three users will automatically start each time the system reboots.

Note: The above three users must have already set the VNC password using the vncpasswd command, otherwise his vncserver boot will fail.

PostScript: I follow the steps above to get everything ready, with the viewer login up, suddenly found a very depressing problem. That is, I can not enter letters and numbers, hurriedly online search, and finally found an article to say this problem. I copy the original text down, of course you can also go here to see: http://blwhome.spaces.live.com/blog/cns!e7ebcdc152b11ff1!401.entry

Unable to enter numbers and letters when using VNC yesterday my friend's machine used VNC to appear a strange problem, what operation is no problem, is unable to enter letters and numbers.       After a long time, finally found the problem. Originally is the input method in mischief.     VNC requires local input methods to match the local operating system language, otherwise this problem occurs.       My friend's system is in English version, when using VNC local Input method switch in Chinese state, if switch to English [UK] This state is no problem. Really toss a long time AH ~ ~ ~ Hope to bring some convenience to other friends ~

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.