7.5. Connecting to Other X Window Systems

 < Day Day Up > 

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. When used with the ssh command, 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 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 button, as shown in Figure 7-6.

Figure 7-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 also need to stop and restart Remote Login using System Preferences Sharing for this change to take effect.


7.5.1. OSX2X

These days, it's fairly common to find a Mac sitting next to a Linux or Unix system 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 right of your destination X11 machine, select West as illustrated in Figure 7-7.

Figure 7-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 -C and paste on the Mac OS X side using -V.

     < Day Day Up > 


    Mac OS X Tiger for Unix Geeks
    Mac OS X Tiger for Unix Geeks
    ISBN: 0596009127
    EAN: 2147483647
    Year: 2006
    Pages: 176

    Similar book on Amazon

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