How to setup VNC

Task: setup VNC in Linux box, so that we can access the Linux box with GUI from windows PC.

On Server Side (Linux):

Install VNC server if it’s not yet installed.

Add allowed VNC client’s IP address in /etc/hosts.allow

Xvnc:  # supposing your PC's address is this one

Set VNC password

> vncpasswd

Start VNC server once to generate startup script, and then stop it

> vncserver
> vncserver -kill :1

Edit startup script: ~/.vnc/xstartup

  • comment out “twm &”
  • add following lines to use Gnome and Chinese/Japanese input methods
export GTK_IM_MODULE="scim"
scim -d &
gnome-session &

Open port 5901 (when needed, 5902/5903/…) in firewall

Start VNC server

> vncserver

On Client Side (PC):


Install VNC client software (such as RealVNC), and connect to Linux server.


Choose “Move | Connect to server” in menu bar, and type in following address:



1. In order to use Chinese/Japanese input method (scim) in Linux, hotkey “<CTRL>-<SPACE>” in PC should be disabled, otherwise scim cannot be launched. This hotkey usually comes from Chinese input method in Windows.

2. In order to input Chinese/Japanese in Linux, on client (PC) side, IME should be turned off (i.e. English).

3. For security reasons, it’s a good practice to start VNC server in Linux only when needed, instead of making it a auto-started service. This can be done with a terminal software (such as PuTTY).

4. I did this because I wanted to access a Linux server from a PC, and I needed Chinese/Japanese support. But after doing so, I found out that PuTTY actually supports Chinese/Japanese: in its config dialog, click “Window | Translation”, then set “Received data assumed to be in which character set” to “UTF-8”. Then the Chinese/Japanese input methods in PC can be used directly in this terminal! (if it still doesn’t work, then do the following two things: 1, click “Windows | Appearance” and choose a proper font; 2, in vi, do “:set enc=utf-8”.)

5. ssh tunneling way to do it:

  • in Cygwin, execute this command: ssh -NTf -L 5901:localhost:5901 <user>@<linux-server-host-name>
  • in command prompt, change dir to “C:\Program Files\RealVNC\VNC Viewer” (or the right place), and execute this command: vncviewer localhost:5901
Categorized as IT Tagged ,