The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]
VNC - allowing remote access to graphical desktops 16 August 2002
Need more help on this topic? Click here
This article has 14 comments
Show me similar articles

VNC (an abbreviation for Virtual Network Computing) is a great client/server software package allowing remote network access to graphical desktops. TightVNC allows you to display X and Win32 desktops on remote X/Win32/Java displays. In short, it will allow me to access my FreeBSD box from my Windows box via an X Windows interface (or the other way around). That's something I've want to do for a while. A friend had told me about VNC, so I went to FreshPorts and did a search for vnc. I chose TightVNC.

You should consider the security implication of using VNC over untrusted networks, such as the Internet. If you plan on using VNC over the Internet, you should use SSH or SSL to secure the session. The documentation will direct you to the right place.

I already had an up to date ports tree, so I installed TightVNC with this single command:

cd /usr/ports/net/tightvnc
make install
My next step was to install the Windows client from the TightVNC download area. Installation was straight forward and I won't document it here. It's Windows. What could go wrong? But, should you need it, there is a TightVNC for Windows document. In my situation, I'll be running the VNC Server on my FreeBSD box, and a VNC Client on my Windows box. You should note that you can do this the other way around and access your Windows box from your FreeBSB box.
Starting the server

On my FreeBSD machine, I did this:

[dan@undef:~] $ which vncserver
/usr/X11R6/bin/vncserver
[dan@undef:~] $ vncserver

You will require a password to access your desktops.

Password:
Verify:
xauth: creating new authority file /home/dan/.Xauthority

New 'X' desktop is undef.unixathome.org:1

Creating default startup script /home/dan/.vnc/xstartup
Starting applications specified in /home/dan/.vnc/xstartup
Log file is /home/dan/.vnc/undef.example.org:1.log

[dan@undef:~] $ ps auwx | grep vnc
ps auwx | grep vnc
dan 41444 0.0 2.5 10824 9796 p0 I 9:18AM 0:36.84 Xvnc :1 -desktop X -httpd /usr/X11R6/share/tightvnc/classes -auth /home/dan/.Xauthority -geometry 1024x768 -depth 24 -rfbwait 120000 -rfbauth /home/dan/.vnc/passwd -rfbport 5901
[dan@undef:~] $
As you can see, the screen was set to 1024x768. I'll look at changing that resolution later. The password you just entered must be supplied when you connect to the server. This password can be changed by running vncpasswd on the server.
Stopping the server

From man vncserver, you will see:

-kill :display
       Stops the session running on the specified display.
So to kill the server, I did this:
vncserver -kill :1
Killing Xvnc process ID 46791
where 1 is the value returned when you started vncserver.
Starting the client

In the following example, I will be using the TightVNC client. I also tried the VNC client from http://www.uk.research.att.com/vnc/. I'm running a client on my Windows box. You should read the TightVNC for Windows document first. I started the VNC Client by clicking on Start->Programs->TightVNC->TightVNC Viewer (Fast Compression). I then entered the details of my VNC Server (undef.example.org:1).

connection details

Then you will be prompted for the session password which you supplied when you started the VNC server. This password can be changed by running vncpasswd on the server.

authentication

If all goes correctly, you should now be looking at an X session running on your FreeBSD box. Here's what it looked like for me:

X session

From here, it's just like you're on the FreeBSD box.

Changing the screen resolution

This was easier than I thought. First, I consulted the vncserver man page. Then I supplied a value for geometry:

[dan@undef:~/.vnc] $ vncserver -geometry 1280x1024

New 'X' desktop is undef.unixathome.org:1

Starting applications specified in /home/dan/.vnc/xstartup
Log file is /home/dan/.vnc/undef.unixathome.org:1.log

[dan@undef:~/.vnc] $
Changing the Window manager
The window manager is started by the ~/.vnc/xstartup script. By default, VNCTight uses twm as that is available on most Unix platforms. Here is the original script:
[dan@undef:~/.vnc] $ less xstartup.original
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
[dan@undef:~/.vnc] $

My window manager of choice is KDE. To use that, I changed twm to startkde. From then on, I got KDE on my VNC:

KDE

VNC Madness
You can connect to the same VNC server session from more than one VNC client. I tried this and fired up more than one client. You can see the same thing happen in all clients.

WARNING: I've been told that if you connect to the VNC server from within a VNC Client, you will hang the system.


Need more help on this topic? Click here
This article has 14 comments
Show me similar articles