LinuxDevCenter.com
oreilly.comSafari Books Online.Conferences.

advertisement


O'Reilly Book Excerpts: Linux Desktop Hacks

Hacking the Linux Desktop

Editor's note: Modifying stuff to suit individual desire is the credo of hackers everywhere. These two excerpts from Linux Desktop Hacks let you modify Linux to suit your desires: control how you access your own desktop, and how users access theirs. (And check back here next week for two more hacks from the book--the first on viewing Microsoft Word documents in a terminal, the second on creating an internet phone.)

Access Windows and Mac OS X from Linux

BeginnerHack 30

Related Reading

Linux Desktop Hacks
Tips & Tools for Customizing and Optimizing your OS
By Nicholas Petreley, Jono Bacon

No need to move to another computer; just sit put and access them all.

Although you don't need to go far to hear someone extolling the benefits of Linux and free software, many people still need to use other operating systems, such as Microsoft Windows and Apple Mac OS X. Aside from personal choice, other reasons to use non-Linux operating systems include running applications that are available only on a particular OS, an employer mandating that you use a particular platform, or even a need to test software and services across different platforms. For some, the solution is a huge desk set up to accommodate three computers with three monitors and three keyboards/mice; however, there is a better way.

This hack uses a piece of software called Virtual Network Computer (VNC). This useful little tool allows you to essentially redirect your monitor output to another computer on a network, and accept keyboard and mouse input from the remote computer. With this software you can run the VNC server on a Windows machine and view the Windows desktop on your Linux machine. Likewise, you can run the VNC server on your Linux machine and view your Linux desktop on a Windows-based desktop. VNC is available for most Unix-based OSes, such as Linux, FreeBSD, Solaris, etc., as well as Microsoft Windows and Mac OS X. VNC gives you the ability to pull together these disparate operating systems on a single desktop.

Configure a Linux VNC Server

VNC comes in a few different guises, but most attention is focused on the RealVNC and TightVNC variants. Of the two versions, TightVNC appears to be the better performer and you can get it from http://www.tightvnc.com/download.html. A number of different packages are available for the supported platforms, and you need both the server (to provide a VNC resource to connect to) and the viewer (to connect to another VNC resource). You should be able to install a recent version of TightVNC using your distributions package manager.

If you run a Mac and want to access your Mac OS X desktop from your Linux machine, you need the OSXvnc package from http://www.redstonesoftware.com/vnc.html as RealVNC and TightVNC do not natively support Mac OS X. A VNC client for Mac OS X is also available within the Fink packaging system at http://fink.sourceforge.net.

To run a VNC server on Linux you must launch the server and give it a special display number to connect to. This usually starts at 1 and increases by one for each new server created. As an example, if you run a VNC server on a machine with the address 192.168.0.2, you would access the first VNC resource as 192.168.0.2:1. To run the server, specify the screen resolution and color depth with the -geometry and -depth command-line options:

foo@bar:~$ vncserver -geometry 1024x768 -depth 24

These settings are parameters for your virtual screen, not the real settings of the machine you are running the server on. This means the physical screen might be displaying an image at 1280x1024 in 8-bit color, but you can view it remotely at 1024x768 in 24-bit color. Of course, the machine you are viewing the image on must support your choices.

TIP: You can specify a nonstandard resolution--for instance, 990x745. Doing this allows you to maximize the size of the remote image on your desktop without obscuring your local desktop's toolbars and panels.

When you first run the server, you are prompted for a password. This password is used to ensure that clients are who they say they are, and the password is stored and remains the same each time you use the VNC server (you can change the password later with vncpasswd if you need to). When the password is successfully entered, the server indicates which display number it has been given.

While the server is running, all applications that are used appear on the VNC display as well as the normal screen on the computer (if a monitor is attached). You can also route applications to display only on the VNC server by using the DISPLAY environment variable and specifying the hostname and display number:

foo@bar:~$ mozilla -display 192.168.0.2:1 &

To stop the VNC server, you need to use the -kill option and the display number assigned earlier when you started the server:

foo@bar:~$ vncserver -kill :1

Connect to a VNC Server

To connect to the VNC server from a Linux machine, you can use the vncviewer tool that is included with the VNC software. This simple little program is used like this:

foo@bar:~$ vncviewer 192.168.0.2:1

In this command, you specify the IP address, a colon (:), and then the display number to connect to. When you run the command, you are prompted for the VNC server password and then the VNC desktop is displayed.

Configure a Windows VNC Server

Installing the Windows VNC server is a fairly painless process. Once installed, it can be configured as a Windows Service so that it is always running (like a daemon in Linux). The benefit of running the server as a service is that you will still be able to access the server when the machine is locked or the user has logged out.

Download the Windows installer from the TightVNC web site. It is a typical Windows installer that offers no surprises.

To use the VNC server as a service, tick each box that refers to the VNC Server System Service in the VNC installation routine. When you have done this, the Server Options dialog box will appear, and you must configure at least the Authentication tab to run the server. In this tab, you should select the VNC 3.3 Authentication option and use the Set Password field to define the password for the server. You should never disable authentication unless you are 100% sure the host network is secure.

To start and stop your server, use the standard Windows Services configuration tool to start and stop the service.

Configure a Mac OS X VNC Server

The official VNC distribution does not include support for Mac OS X; however, a VNC server is freely available from Redstone Software (http://www.redstonesoftware.com/vnc.html), called OSXvnc. This software is available as a Mac OS X disk image file (.dmg). Download the software and then double-click it in the Finder. A window will pop up with the program inside it; drag the program to the desktop. Now if you double-click the icon on the desktop, the VNC Settings dialog will appear. For a quick and easy VNC connection, the defaults are fine, and you can just click the Start Server button to begin the connection.

View Your Desktop in a Web Browser

One intriguing feature of the VNC server is that it includes a small web server that exports the VNC desktop to a browser using a special Java applet. To access your VNC server, connect to port 5801 with a Java-enabled web browser. This port number is appended to the hostname/IP address in the same way as a normal web resource:

http://foo.com:5801

This port number actually maps to the VNC display you are running. If you are running display number 1, use port 5801; display number 2 is port 5802, etc.

TIP: Some distributions, notably Debian, package the Java applet separately from the VNC server package.

When you are running any server on the Internet, you should take steps to ensure that it is protected with a firewall. A firewall keeps all unwanted traffic away from your server. If you are running a firewall already, you should ensure that ports 5800-5805 are available for use. If you want to be extra secure, only open port 5801 for use and make sure you always run off desktop number 1. Another option is to encrypt your VNC connection with an SSH tunnel [Hack #32] .

Pages: 1, 2

Next Pagearrow




Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!


Linux Resources
  • Linux Online
  • The Linux FAQ
  • linux.java.net
  • Linux Kernel Archives
  • Kernel Traffic
  • DistroWatch.com


  • Sponsored by: