x2x is a software alternative to a KVM switch

2606

Author: David Pendell

Unless you have fully embraced the virtualization movement, you probably have more than one machine in your home or office, particularly if you run more than one operating system, and you probably have more than one keyboard and mouse on your desk. If you would like to regain some desk space without having to purchase a KVM switch, x2x may be the solution. Simply put, x2x takes advantage of the X Window System’s ability to run a display over a TCP/IP network. In this case, you are not running a display as much as you are taking charge of another display’s mouse and keyboard.

You can run x2x over SSH, which is easy and secure, or connect x2x directly to the remote X server. The second method is a bit more difficult because it requires some reconfiguring of your X system, but it gives you the ability to cut and paste between the systems. If you want x2x to be as secure using the second method as it is with the first, you have to resort to SSH port forwarding, which may be difficult because x2x does not use a consistent port on the primary machine. In either case, the machines that run x2x have to support the XTEST X Window extension. Most Linux distributions do; to see if yours does, run the command xdpyinfo | grep XTEST in a terminal. If you get any response, you are over the first hurdle.

To install x2x in Ubuntu or any Debian-based distro, run the command sudo apt-get install x2x. Unfortunately, Fedora 9 does not include x2x, but Fedora 8 does, and it installs in Fedora 9 without dependency problems. I used the package from the Dries RPM repository. For any other distro, look for x2x in the package manager. Compiling from source may not be an option, because the download links on the project’s home page don’t lead you to the code. The project hosts a Mercurial repository, but the code there is for the unstable 1.30 beta version. If you want the stable 1.27 code, you will have to look for it in a distro repository. The two versions of x2x use different protocols, so make sure the versions on your machines match.

To use x2x, you need to have a secure shell daemon running on the remote machine. For both Ubuntu 8.04.1 and Fedora 9, the SSH daemon should already be installed. If it’s not, in Ubuntu, either install it using Synaptic, or run the command sudo apt-get install ssh. For Fedora, run the command sudo yum install openssh.

One additional caveat: If you are using a login manager such as gdm, you must enable remote TCP connections to the X server. In Ubuntu 8.04.1 run the command sudo /usr/sbin/gdmsetup. Select the Security tab and uncheck the “Deny TCP connections to the Xserver” checkbox. For Fedora and other distros, consult the documentation for the X server and login manager. A quick check of netstat -a | grep x11 will tell you if you need to investigate further. If the result comes back containing LISTEN, you should be ready to go.

Once all of the dependencies are satisfied, setting up method one is simple. First, determine the orientation of the displays — will the remote display be north, south, east, or west of the primary machine? On the machine that hosts the keyboard and mouse, run the command:

ssh -X remote_machinename_or_ip_address x2x -direction_of_the_remote_display -to :0

On my test machine, since the remote display was to the left of the primary display, I used the -west option. If all goes well, a prompt for your password on the remote machine should follow. Enter it, and you should be able to move the mouse to the edge of the primary display and have it appear on the remote display.

One advantage to this method is that the only machine that requires x2x to be installed is the remote machine. As a test, I disabled x2x on the primary system and tried connecting and running x2x through SSH. It worked perfectly. This is very handy if the primary machine limits your access to configuration files.

Method two is a little more complex, but potentially worth it if you can gain the ability to do cut and paste between machines. On my test rig I was never able to get that functionality working, and unfortunately, good documentation for x2x is limited.

With the second method, before you can connect to the remote display, you have to add the IP address or hostname of the primary machine to the xhost authentication on the remote machine or the primary machine will be denied access. To do so, run xhost IP_or_hostname at the command line on the remote machine. If there are no errors, carry on; otherwise, look into security settings on the remote machine. Once you’re successful, run the following command on the primary machine:

x2x -to IP_or_hostname:0.0 -direction_of_the_remote_display

You should then be up and running. Move the mouse to the edge of the screen in the direction that you chose. If all goes well, the mouse will disappear from the primary machine and appear on the remote machine. Try cutting and pasting; if it works, great! If not, well, don’t say I didn’t warn you.

If all you want is quick access to more than one display on different machines with one keyboard and mouse, x2x works well, particularly if you have root access to only the remote machines. If you absolutely must have cut and paste, or your machine mix includes Mac OS X, you may want to consider Synergy instead.

Categories:

  • Tools & Utilities
  • Desktop Software