Tightvnc

From ArchWiki

Jump to: navigation, search


Contents

What is it?

TightVNC is a VNC (Virtual Network Computing) Unix server and viewer. It is a remote display program that allows you to run totally parallel sessions on a machine which you can access from anywhere on a LAN or over the Internet. The server and all applications your start continue to run on it even when you disconnect. This is NOT the same as controlling the desktop that is being displayed on the local monitor/LCD. To do this, see the [connecting to the root desktop] section of this article.

Again, these vncserver run totally in parallel to your desktop session. You can also have multiple servers running simultaneously on the same machine (each on a different port). To improve security of sessions VNC can be piped through SSH (Secure SHell).

How to Install on Arch

To install TightVNC type the following:

# pacman -S tightvnc

Now you need to set it up to work as either a server or client/viewer.

VNC Server on Linux (Arch)

First open up a terminal and type in:

$ vncserver

You will now be prompted for a password:

You will require a password to access your desktops.

Password: 
Verify:   

Then you will be asked if you would like to enter a view only password. This allows two different ways of accessing a desktop on your system.

  • Allow a user to log into your VNC server and be able to fully use the desktop.
  • Allow a user to log into your VNC server and be only allow to view the desktop.

I chose 'n' no for this example.

Would you like to enter a view-only password (y/n)? n

Now the vnc server desktop is created:

New 'X' desktop is hostname:1

Creating default startup script /home/user/.vnc/xstartup
Starting applications specified in /home/user/.vnc/xstartup
Log file is /home/user/.vnc/hostname:1.log

The problem now is that the VNC server is running but it is not running any desktop. If you were to log in now from a different computer you would only see the console.

Adding a Desktop to a VNC server

Since we want to use desktop with the VNC server kill the existing server that is running:

$ vncserver -kill :1

Since it was the first VNC server we created it had the number :1. On Linux systems you can have as many VNC servers running as you want. To kill a specific server you will need to specify its number.

The first time we ran the vncserver, the .vnc directory was created with some files inside of it. We will now go into this directory and edit these files as to add a desktop to the VNC server.

$ cd /home/user/.vnc
$ nano xstartup
#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

The xstartup file works just like a .xinitrc file. Clear it out and add the appropriate exec line for your desktop environment, and whatever other programs you wish to start. The following setup is for a gnome session.

#!/bin/sh
xrdb $HOME/.Xresources&
exec gnome-session
#exec openbox-session   #for an openbox desktop
#startxfce4    #for an xfce desktop
#exec icewm  #for an icewm desktop
#startkde    #for a kde desktop

Fixing a Gnome/tightvnc Keyboard Mapping Problem

Description of problem

The way gnome initializes keyboards via the gnome-settings-daemon under a vnc session is known to scramble keyboard maps. When a user connects to the vncserver, the keyboard map is all messed up, e.g. typed characters do not reflect the key the users presses. The problem ONLY affects the vnc-session, NEVER the live session.

For example, one types "asdf" it gets printed as "abfh" Similarly, "qwert" becomes "c.gvn"

Other DEs such as fluxbox and xfce4 don't seem to have this problem. At this point, no one has reported whether KDE has a problem or not.

Method 1

This fix reported in [this ubuntu bug report] works on Arch. The 55th post teaches to add the following to ~/.vnc/xstartup before the last line.

export XKL_XMODMAP_DISABLE=1

Example of a complete ~/.vnc/xstartup using this method:

#!/bin/sh
xrdb $HOME/.Xresources
export XKL_XMODMAP_DISABLE=1
exec gnome-session

Method 2

Acknowledgments to [max.bra] who proposed the following solution in [this thread] which is also confirmed to work under Arch.

  1. Log into another tty as the user you wish to use for starting vnc-sessions
  2. Stop GDM
  3. Paste the two line fix into the shell
  4. Restart GDM
Note: Repeat the above procedure for each user you wish to use to start vnc-sessions
gconftool-2 --set /desktop/gnome/peripherals/keyboard/kbd/layouts --type List --list-type String [aa]
gconftool-2 --set /apps/gnome_settings_daemon/plugins/keyboard/active --type boolean false

Securing vnc by ssh

This is trivial to do. Simply ssh into your remote box using some switches that specify the port the vnc server is running on (5901 is the default) and the port on your localhost you want it connected to.

$ ssh IP_OF_REMOTE_SYSTEM -L 8900/localhost/5901

The above line will cause your ssh session to tunnel port 5901 from the remote PC to 8900 on your localhost. Then run vncserver in the same shell. To connect to the now encrypted vnc session, do NOT close your ssh session! Open a new shell and connect to localhost:8900 like so

$ vncviewer localhost:8900

Connecting to the root (:0) desktop

When you connect to vncserver with your client, by default you are given a new X session with your own desktop. This means that a person who is physically sitting in front of the server will not see your remote session, and vice-versa you cannot see or interact with the root (:0) or physical desktop.

If you would like to remote into a machine with vnc and actually see and interact with the root desktop you can use x11vnc, which provides access to the root (:0) desktop by default. A person sitting in front of the server will see your actions, such as the mouse moving etc.

x11vnc is very similar to setup, and you can use the same clients as vncserver.

Using xf4vnc (for ttf fonts and other improvements)

Xf4vnc provides an Xvnc server that is capable of displaying ttf fonts, and other improvements over tightvnc. However the package in arch only comes with the Xvnc binary, and none of the vnc* scripts. This can be worked around by installing tightvnc and replacing /usr/bin/Xvnc with the one from xf4vnc.

  • Install xf4vnc-xvnc, and copy /usr/bin/Xvnc to a local directory
  • Uninstall xf4vnc-xvnc, install tightvnc, and copy the local Xvnc to /usr/bin/Xvnc
  • Edit /usr/bin/vncserver, and comment out the -co line (this parameter has been removed in xf4vnc)

Start vncviewer as normal, and it should work.

Personal tools