synergy — open source keyboard-mouse switch software 

A KVM (keyboard video mouse) hardware device can be used to share the same keyboard, display, and mouse between many computers. In contrast, synergy is a software solution that enables sharing, between many computers, of the same mouse and keyboard but not the screen. Synergy can be thought of as software-based KVM switch, but without the display capability. This means that each of the computers that the mouse and keyboard are shared between needs its own monitor. The main advantage of this approach, over solutions such as VNC, is the raw speed. Mouse and keyboard device inputs are efficiently compressed and transmitted over the network without the overhead of bulky video. An advantage over hardware KVM is that synergy is an open source project and thus the software can be downloaded and used free of charge.

Installing Synergy Software

You can install synergy on your Linux distro using one of the following commands.

sudo yast2 --install synergy    # on Novell's openSUSE
sudo yum install synergy        # on RedHat's Fedora
sudo apt-get install synergy    # on Ubuntu

Alternatively, you can download and compile synergy's source distribution which is located at the following url: http://synergy2.sourceforge.net/download.html. The compilation process is straightforward altough you may have to install some dependencies if any are missing. The basic steps to download, compile and install synergy are as follows.

wget http://optusnet.dl.sourceforge.net/sourceforge/synergy2/synergy-1.3.1.tar.gz
tar xzf synergy-1.3.1.tar.gz
cd synergy-1.3.1
./configure
make && sudo make install

Synergy comes with server and client binaries: synergys and synergyc, respectively. Note that synergy has to be installed on the server as well as on all of the client computers.

Configuring Synergy Software

Configuration of synergy software is quite simple. All you have to do is create a small config file in your home directory called synergy.conf. The format of this file is as follows.

section: screens
    server_hostname:
    client_hostname:
end
section: links
    server_hostname:
        right = client_hostname
    client_hostname:
        left = server_hostname
end

In the above the server_hostname and client_hostname should be replaced with the output of the hostname command run on the server and the client computers, respectively. Note that the screens section lists all of the screens and the links section defines the relative position of the screens. Also worth a mention is the fact that this simple example has two screens listed, however it is possible to have more than two.

Running Synergy as a Foreground Process

We are now ready to run synergy on both server and client PCs. To start we'll run them as forground processes to make sure they work correctly and then we'll run synergy server and client as daemons. The following command is used to run the synergy server with a specific config file.

synergys -f --config ~/synergy.conf

Note that the mouse and keyboard of the synergy server PC will be used as inputs for all of the synergy client PCs. The above command produced the following debug output.

INFO: synergys.cpp,1042: Synergy server 1.3.1 on Linux ...
DEBUG: synergys.cpp,1051: opening configuration "synergy.conf"
DEBUG: synergys.cpp,1062: configuration read successfully
DEBUG: CXWindowsScreen.cpp,840: XOpenDisplay(":0")
DEBUG: CXWindowsScreenSaver.cpp,339: xscreensaver window: 0x00000000
DEBUG: CXWindowsScreen.cpp,110: screen shape: 0,0 1280x800
DEBUG: CXWindowsScreen.cpp,111: window is 0x02600004
DEBUG: CScreen.cpp,38: opened display
DEBUG: CXWindowsScreen.cpp,672: registered hotkey ScrollLock (id=ef14 mask=0000) as id=1
NOTE: synergys.cpp,500: started server

Next, to start the synergy client software on a client PC the following command is used.

synergyc -f server_hostname

Where server_hostname should be replaced with the hostname or IP of the server PC. Here is a debug output of the above command.

INFO: synergyc.cpp,716: Synergy client 1.3.1 on Linux ...
DEBUG: CXWindowsScreen.cpp,840: XOpenDisplay(":0.0")
DEBUG: CXWindowsScreenSaver.cpp,339: xscreensaver window: 0x00000000
DEBUG: CXWindowsScreen.cpp,110: screen shape: 0,0 1280x1024
DEBUG: CXWindowsScreen.cpp,111: window is 0x03400004
DEBUG: CScreen.cpp,38: opened display
NOTE: synergyc.cpp,330: started client
WARNING: synergyc.cpp,265: failed to connect to server: Timed out
DEBUG: synergyc.cpp,237: retry in 1 seconds
WARNING: synergyc.cpp,265: failed to connect to server: Timed out
DEBUG: synergyc.cpp,237: retry in 3 seconds
WARNING: synergyc.cpp,265: failed to connect to server: Timed out
DEBUG: synergyc.cpp,237: retry in 5 seconds
NOTE: synergyc.cpp,247: connected to server

Notice how the debug output above shows that the synergy client has trouble connecting to the synergy server (shown in red). This can be caused by restrictive firewall settings. The synergy client connects successfully once the server and client firewalls are configured to allow connections between each other (shown in green). So this is it, you now should be able to move your mouse beyond the left edge of the the screen and it should appear on the client's monitor. Once the mouse pointer is on a client display, then any server keyboard inputs are also redirected to that client. Synergy software also caters for sharing of the clipboard buffer, which comes in very handy. You can copy something on one computer and then paste it on another.

Running Synergy as a Daemon

Once you are happy that everything is working OK, you can run synergy server and client as daemons. That way they will remain resident in the background without consuming an active shell session. The following command is used to run synergy server as a daemon on a PC acting as a synergy server.

synergys --config ~/synergy.conf

To run synergy client as a daemon on a client PC the following command is used.

synergyc server_hostname

Where server_hostname should be replaced with the hostname or IP of the server PC.

Automating Synergy via .bashrc Function

I wrote the following bash function to start and stop synergy server and client(s). Note that WordPress filters quotes, dashes and other characters and replaces them with different ones. This looks alright on a html page, but causes serious problems when compiling or running the code. So if you would like to use the function below then download the unfiltered source code here: synergy.sh. To make synergy function available from bash shell run source synergy.sh or place the function in your ~/.bashrc file.

synergy()
{
    if [ "$1" == "" ] || [ "$1" == "start" ] || [ "$1" == "restart" ]; then
        #synergy stop;
 
        echo -n 'Starting local synergy server… ';
        synergys –config ~/synergy.conf;
        echo 'done.';
 
        echo -n 'Starting remote synergy clients… ';
        ssh kamil@132.234.99.123 'synergyc 132.234.99.122';
        # … insert extra client entries here
        echo 'done.';
    else
        if [ "$1" == "stop" ]; then
            echo -n 'Stopping local synergy server… ';
            killall -TERM synergys;
            echo 'done.';
 
            echo -n 'Stopping remote synergy clients… ';
            ssh kamil@132.234.99.123 'killall -TERM synergyc';
            # … insert extra client entries here
            echo 'done.';
        else
            echo 'usage: synergy [[start]|stop]';
        fi
    fi
}
 

Note that in the above example the username used for ssh is kamil, the IP of the synergy server is 132.234.99.122 and the IP of the synergy client is 132.234.99.123. You will have to change the usernames and hostnames to suit. If you do not want to type in the password for the client PC each time you start or stop synergy then consider using key authentication over ssh.

The above bash function is used as follows. To start both synergy server and client run the following command.

synergy

This produces the following output.

Starting local synergy server... done.
Starting remote synergy clients... done.

To stop both synergy server and client, pass the stop option to the bash macro.

synergy stop

If all goes well the following will be displayed.

Stopping local synergy server... done.
Stopping remote synergy clients... done.

If for some reason the connection to the client PC is not available, then the following errors will be produced when starting synergy:

Starting local synergy server... done.
Starting remote synergy clients...
ssh: connect to host 132.234.99.123 port 22: No route to host
done.

or when stopping synergy:

Stopping local synergy server... done.
Stopping remote synergy clients...
ssh: connect to host 132.234.99.123 port 22: No route to host
done.

That's it. Hope you enjoy synergy!


Did you find the above information useful and interesting? If so, please support this site by using the blog directory links at the bottom of this page. Thanks for your support!

If you have any Linux related problems or questions then please feel free to post them on our Linux Forums: http://linux.dsplabs.com.au/forums.




VPS Hosting Referral Code DZZCC3

Add me to Technorati Favorites Vote for me on Blog Catalog

3 Responses to “synergy — open source keyboard-mouse switch software”

  1. Anjin Says:

    Very good article!

  2. Victor Trac Says:

    Thanks for the script. I modified it a bit to work well on OS X (Synergy doesn't daemonize on OSX) and created a special non-passphrase encrypted ssh key just for synergy to my clients. It works well.

  3. Setting up some Synergy | The Linux Experiment Says:

    […] able to set up a neat little program that I think you should all know about! Synergy allows you to set up two or more computers so that they all share one keyboard and one mouse. Even better it works cross […]

Leave a Reply