5.6 Connecting to Other X Window Systems

You can connect from Mac OS X to other X Window systems using ssh with X11 forwarding. If you use OpenSSH (which is included with Mac OS X), you must use the - X option to request X11 forwarding (the - 2 option specifies the SSH Version 2 protocol, as opposed to the older Version 1 protocol). For example:

 $  ssh -2 -X   remotemachine   -l   username    

As long as X11 is running, this can be entered in either an xterm window or in the Terminal. To have the X11 forwarding enabled in Terminal, you must have the DISPLAY variable set prior to making the connection. Under the bash shell (and other Bourne-compatible shells ) use:

 DISPLAY=:0.0; export DISPLAY 

Under csh and tcsh , use:

 setenv DISPLAY :0.0 

It is also possible to create a double-clickable application that connects to a remote machine via SSH 2, with X11 forwarding enabled. For example, you can use the following script for this purpose:

 #!/bin/sh  DISPLAY=:0.0; export DISPLAY /usr/X11R6/bin/xterm -e ssh -2 -X   remotemachine   -l   username   

If you've installed the commercial version of SSH from http://www.ssh.com, the equivalent of the preceding script is as follows :

 #!/bin/sh  DISPLAY=:0.0; export DISPLAY /usr/X11R6/bin/xterm -e ssh2   remotemachine   -l   username   

The X11 forwarding flag is +x with the commercial SSH, but it is enabled by default, so that you need not include it in the command.

Using Apple's X11, you can add an Application menu item to accomplish the same task. To do this, start by saving the above script to whatever you'd like to call this application. For example, suppose we want to connect to a remote machine named mrchops with a username of eer . We'll name the application sshmrchops and save it as ~/bin/sshmrchops.sh . In X11, select Applications Customize, and then click the Add Item button, as shown in Figure 5-6.

Figure 5-6. Adding an item to the X11 application menu

That's it! Now you'll be ready to launch the connection to the remote machine via the menu bar and the Dock. Once you've connected to a machine running X11, you can start X11-based applications on the remote machine and display them on your Mac OS X machine.

You can also do the reverse (SSH to your Mac and run X11 applications on the Mac, but display them on the local machine), but be sure to edit /etc/sshd_config and change this line:

 #X11Forwarding no 

to this:

 X11Forwarding yes 

You will also need to stop and restart Remote Login using System Preferences Sharing for this change to take effect.

5.6.1 OSX2X

These days, it's fairly common to find a Mac sitting next to as many as four Linux or Unix systems, each running an X11-based desktop. You may also have more than one Mac on your desk. In such situations, it would be convenient to use only one keyboard and mouse to control all of your Mac OS X and X11-based desktops, saving valuable desktop space. Enter Michael Dales' free BSD-licensed application osx2x (http://opendarwin.org/projects/osx2x/).

To use this handy little application, log into your Linux/Unix box running an X11 server, and enter the command:

 xhost + mymachost 

Then, double-click the osx2x application, and once the main window appears, click New Connection to open a drop-down window. In the drop-down window's Hostname field, supply the hostname or IP address of the Unix box running the X11 desktop, followed by either :0 or :0.0 (without any spaces), as in myhost:0.0 . Next, select the Edge detection (East, West, North, or South), and the connection type X11. If, on the other hand, you are connecting your Mac to a machine running a VNC (Virtual Network Computer, described in the next section) server (for example, another Mac), select VNC as the Connection type rather than X11, and enter the VNC server password. You can switch back and forth between the Mac and the remote machine with Control-T, or you can enable edge detection and choose the position of your X11 system relative to your Mac. For example, if your Mac is to the left of your destination X11 machine, select East as illustrated in Figure 5-7.

Figure 5-7. Controlling a neighboring X11 desktop with osx2x

In addition to using one keyboard and mouse to control up to four systems, you can use osx2x to copy text from an x11 clipboard using figs/command.gif -C and paste on the Mac OS X side using figs/command.gif -V.

Mac OS X Panther for Unix Geeks
Mac OS X Panther for Unix Geeks
ISBN: 0596006071
EAN: 2147483647
Year: 2003
Pages: 212

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net