Usage of vnc
A. Server machine
- First set a password with vncpasswd. The password is stored
encrypted
in the .vnc directory in the file passwd.
- Start a vnc session with e.g:
vncserver -geometry 1600x1200 -depth 24
- You can choose a different window size (e.g. 1024x768), the depth
specifies
the color depth.
- The session can be killed with:
vncserver -kill :1
- The :1 indicates that the session made use of screen 1. This is
the
default value you get when starting a session. If there is another user
running
VNC you will get another screen number, at the start of the VNC session
the
number is specified. Note that the server continues to run at logout.
At
any time one can disconnect from the server while the session continues
to
run, the connection can be re-established again later and from another
client
machine as needed.
- After starting the session the X window manager specified in
~/.vnc/xstartup
will be started. The xstartup file could contain this:
#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &
- The xstartup file as listed above causes starting of the XFCE environment. Replace "startxfce4 &"
by
"startkde &" to start up the complete KDE environment, by "exec
gnome-session &"
to start up GNOME or by "mvm &" and "konsole &" to start the Motif Windows manager and the KDE terminal (on a solid grey background if "xsetroot -solid grey" is added to the xstartup file)
- In case of problems with fonts add this to the xstartup file:
xset +fp /usr/share/X11/fonts/misc
xset +fp /usr/share/X11/fonts/75dpi
The paths specified may need to
be adapted, the paths above are correct for SLC5.
B. Client machine
- Windows: download and install VncViewer (choose
"Products"
and then "free edition")
- Linux: use vncviewer, probably already installed (if not, click here and choose
"Products"
and then "free edition"), as follows:
vncviewer xxx:N
- with xxx the name of the machine to connect to and N the screen
number
In all cases the machine running the server should be specified as well
as
the screen number.
C. Tunneling
A direct connection to the server program may not be possible, in that
case
tunneling via ssh can be used. This also provides more safety, as the
connection
via ssh is encrypted. To make clear how this works consider the
following
example: a VNC connection to a machine with name tarfa
should
be established via a login server with name "login" in the domain
nikhef.nl:
Login to login.nikhef.nl as follows:
ssh -l username -L 5901:tarfa.nikhef.nl:5901 login.nikhef.nl
Then ssh to tarfa and open a VNC session there, as explained under A.
Next
connect your viewer to localhost and everything should work, if the VNC
session
is on screen 1. If it is on screen N instead of 5901 5900+N (that is
the
result of adding N to 5900) should be specified in the ssh command
shown
above. Note that under Windows the ssh command cannot be given
directly,
one can use either a special ssh program or install Cygwin and use the Cygwin console to
give
this command. MacOS X comes with a VNC server which uses screen 0, to
switch
the server on go to "System Preferences", "Sharing" and select "Screen
Sharing".
D. Useful scripts
On the server machine:
startvnc: starts a vnc sesssion
stopvnc: stops vnc session usng screen 1
stopvncn N: stops vnc screen N
Contents of these scripts (geometry defines the maximum size if the
window in pixels, depth refers to the number of bits used for defining
colors):
startvnc: vncserver -geometry 1880x1160 -depth 24
stopvnc: vncserver -kill :1
stopvncn: vncserver -kill :$1
On the client machine:
For setting up a tunnel to Nikhef:
vnc tarfa: sets up a tunnel to machine tarfa, screen 1, localhost screen 1
vncn tarfa N: sets up a tunnel to machine tarfa, screen N, localhost screen N
vnc2 tarfa: sets up a tunnel to machine tarfa, screen 1, localhost screen 2
Contents of these scripts:
vnc: ssh -l user -L 5901:$1.nikhef.nl:5901 login2.nikhef.nl
vncn ssh -l user -L 590$2:$1.nikhef.nl:590$2 login2.nikhef.nl
vnc2: ssh -l user -L 5902:$1.nikhef.nl:5901 login2.nikhef.nl