SynergyHowto

Revision 4 as of 2005-08-14 08:17:06

Clear message

Synergy? What is Synergy? Synergy is a program that will let you use one keyboard and mouse on multiple computers accross a network. The computers can be running Linux, Windows, or MacOS. In this howto I will let you know how to get Synergy setup and running on your Ubuntu system.

Warning! Achtung! Synergy is not very secure at all! Consider - you are setting up something to allow an entirely different computer control the keyboard and mouse on your own computer! Don't try and use this anywhere unsecure! There is a way of making it a bit more secure by running it over OpenSSH, but that is currently beyond the scope of this article. Feel free to read the documentations at the Synergy website.

Obtaining Synergy

There are a few ways to get Synergy, one of the hardest is to actually get the source code from the Synergy website at http://synergy2.sourceforge.net/index.html, re-compile it, set it up and run it from the command line. But that's the hard way, and we don't like the hard way! The easy way is to install an apt package that has already been prepared by Daniel Lutz. More information than you neeed/want to know about this 'universe' package can be found at http://packages.ubuntu.com/hoary/net/synergy. This guide will explain how to install and use this package.

The first thing that needs done is to actually install the package. There are two ways of doing this, through the command line, or through Synaptic Package Manager.

Synaptic Package Manager

Note: you will need to be connected to the internet for this.

1. Add the universe package repository to your repository list. If you have not done this already, you can find out how to do it at: UniversePackages

2. Click the icon at the top, and select Search. In the field type "synergy".

3. Click the box next to synergy, and select mark for installation. If your search for synergy comes up blank, check for obvious mistakes first, such as the spelling of synergy, and then make sure that you have correctly added the universe repository to your repository list.

4. Click the Apply icon at the top and watch it install.

Command Line Interface

Remember, Synergy is kept in the universe package list, so you will have to uncomment the universe repositories in /etc/apt/sources.list. If you don't know how to do it, this is how:

You will need to open /etc/apt/sources.list in a test editor, I will use nano.

bash:~$ sudo nano -w /etc/apt/sources.list

Now you will want to look for the commented out, universe repository. It will look like this.

#deb http://archive.ubuntu.com/ubuntu warty main restricted universe
#deb-src ftp://archive.ubuntu.com/ubuntu warty main restricted universe

and make them look like this.

deb http://archive.ubuntu.com/ubuntu warty main restricted universe
deb-src ftp://archive.ubuntu.com/ubuntu warty main restricted universe

Now to save in nano you will want to ctrl-o then ctrl-x, that will save and exit nano.

You now need to update your sources.

bash:~$ sudo apt-get update

Your apt repositories are now up to date so that we can install Synergy now.

bash:~$ sudo apt-get install synergy

That will do it for the install on Ubuntu. To install on another source, like windows, please take a look at the [http://synergy2.sourceforge.net/index.html Synergy site]

Configuring Synergy

Now that Synergy is installed, what you need to do is configure it. BUT, you have to configure at least two machines because without two machines using Synergy makes no sense. I will show you the configuration for a server and a client. I will only show the Ubuntu configuration's, please refer to the [http://synergy2.sourceforge.net/index.html Synergy] site for instructions on configuring other systems.

Server Configuration

Here is a copy of my server's configuration.

section: screens
        ubuntu42:
        arthur:
end
section: links
        ubuntu42:
                right = arthur
        arthur:
                left = ubuntu42

end

The meaning of the names in the configuration are as follows. Ubuntu42 is my main machine which acts as a server for Synergy. Arthur is the client(another Ubuntu machine(laptop)) that I use my desktop's keyboard and mouse with. Section is where you lay out different configurations Screens is where you set the host names of the computers going to be used. Links is what side the mouse will leave the screen of one computer to reach the desktop of the other. So Ubuntu42 is set to the left of Arthur, so when I drag the mouse off the right hand side of Ubuntu42's screen it appears on Arthur's left hand side of the screen. And vice versa. You can set the Links to go out the top of the screen and come in the top of the other screen, you can also set up multiple computers. Multiple here, of course, meaning more than two.

Client Configuration

There is none Smile :) you just install

Running Synergy

From the server you run the command

bash:~$ synergys -f --config synergy.conf

and that will start running the server.

From a client(In this howto the client being Ubuntu), you would issue the command

bash:~$ synergyc -f <ip address of server>

and that will start the client looking for the server of said address.

Note: the -f command tells Synergy to run it from a terminal window.

Completing your setup

You probably don't want to have a synergy terminal window open all of the time, so your next step will be to set it up to run as a service.

For those of you who are using a Windows machine as well as Ubuntu, a little gotcha is that when you set Synergy to run at startup, you will also have to start the service in Control Panel -> Administrative Tools -> Services, or by rebooting your computer.

Adding Synergy as an autostaring feature of Gnome is a bit more complicated.

But not too painful if you are familar with how Gnome handles login scripts.

The easiest way is probably to pop open a terminal and type the appropriate line without the '-f' option, then you can safely close the terminal and Synergy will continue to run.

If you use some sort of graphical login screen, it is pretty easy to have it autostart. You add a little script in the /etc/X11/Xsession.d folder with a command that says to run it with the bash shell, and then the bash command you use to start synergy.

The name and location of this file is crucial! The file must start with two digits, to specify the order. It really doesn't matter where it is or what the rest of the name is though. I named mine 12synergy, 22synergy, 32synergy and 54synergy. Sadly, this does not allow you to use synergy on the login screen, but there is a way to do this fortunately for those whom need a way to also use the keyboard prior to final login. You are going to also edit 2 existing files within the X11 directory pertaining to gdm.

For a client, your new file should look like this, where xxx.xxx.xxx.xxx is the ip address of your server:

#/bin/bash
/usr/bin/killall synergyc
sleep 1
/usr/bin/synergyc xxx.xxx.xxx.xxx

Warning: if you put the -f into the command, you'll get a script that doesn't stop and let gnome finish loading!

We want the client to be running when gdm is running, prior to logging in. Add the following to /etc/X11/gdm/Init/Default: (just add them to the top of the file)

/usr/bin/killall synergyc
sleep 1
/usr/bin/synergyc xxx.xxx.xxx.xxx

For the client file we must also edit the PreSession script to kill our synergy process running as root before the Xsession scripts run it as user. The file is /etc/X11/gdm/PreSession/Default and it should look like this:

#
# Note that any setup should come before the sessreg command as
# that must be 'exec'ed for the pid to be correct (sessreg uses the parent
# pid)
#
# Note that output goes into the .xsession-errors file for easy debugging
#
PATH="/usr/bin/X11:/usr/X11R6/bin:/opt/X11R6/bin:$PATH:/bin:/usr/bin"

gdmwhich () {
  COMMAND="$1"
  OUTPUT=
  IFS=:
  for dir in $PATH
  do
    if test -x "$dir/$COMMAND" ; then
      if test "x$OUTPUT" = "x" ; then
        OUTPUT="$dir/$COMMAND"
      fi
    fi
  done
  unset IFS
  echo "$OUTPUT"
}

# synergyc process, running as root, ends here. This is the last script in the gdm login sequence before things start running as user.
/usr/bin/killall synergyc
sleep 1

XSETROOT=`gdmwhich xsetroot`
if [ "x$XSETROOT" != "x" ] ; then
        # Try to snarf the BackgroundColor from the config file
        BACKCOLOR=`grep '^BackgroundColor' /etc/gdm/gdm.conf | sed 's/^.*=\(.*\)$/\1/'`
        if [ "x$BACKCOLOR" = "x" ]; then
                BACKCOLOR="#76848F"
        fi
        "$XSETROOT" -cursor_name left_ptr -solid "$BACKCOLOR"
fi


SESSREG=`gdmwhich sessreg`
if [ "x$SESSREG" != "x" ] ; then
        # some output for easy debugging
        echo "$0: Registering your session with wtmp and utmp"
        echo "$0: running: $SESSREG -a -w /var/log/wtmp -u /var/run/utmp -x \"$X_SERVERS\" -h \"$REMOTE_HOST\" -l \"$DISPLAY$
        exec "$SESSREG" -a -w /var/log/wtmp -u /var/run/utmp -x "$X_SERVERS" -h "$REMOTE_HOST" -l "$DISPLAY" "$USER"
        # this is not reached
fi

# some output for easy debugging
echo "$0: could not find the sessreg utility, cannot update wtmp and utmp"
exit 0

Warning: if you put the -f into the command, you'll get a script that doesn't stop and let gnome finish loading!

For a server, it should look something like this:

Recap: Name this file 12synergy and place it into the /etc/X11/Xsession.d directory!

#/bin/bash
/usr/bin/killall synergys
sleep 1
synergys --config /full/path/to/synergy.conf

Warning: if you put the -f into the command, you'll get a script that doesn't stop and let gnome finish loading!

Recap: The server file we must edit, it is contained within /etc/X11/gdm/PreSession/Default file!

#
# Note that any setup should come before the sessreg command as
# that must be 'exec'ed for the pid to be correct (sessreg uses the parent
# pid)
#
# Note that output goes into the .xsession-errors file for easy debugging
#
PATH="/usr/bin/X11:/usr/X11R6/bin:/opt/X11R6/bin:$PATH:/bin:/usr/bin"

gdmwhich () {
  COMMAND="$1"
  OUTPUT=
  IFS=:
  for dir in $PATH
  do
    if test -x "$dir/$COMMAND" ; then
      if test "x$OUTPUT" = "x" ; then
        OUTPUT="$dir/$COMMAND"
      fi
    fi
  done
  unset IFS
  echo "$OUTPUT"
}
#Synergy Server Starts at login and dies at logoff!
/usr/bin/killall synergys
sleep 1
synergys --config /full/path/to/synergy.conf


XSETROOT=`gdmwhich xsetroot`
if [ "x$XSETROOT" != "x" ] ; then
        # Try to snarf the BackgroundColor from the config file
        BACKCOLOR=`grep '^BackgroundColor' /etc/gdm/gdm.conf | sed 's/^.*=\(.*\)$/\1/'`
        if [ "x$BACKCOLOR" = "x" ]; then
                BACKCOLOR="#76848F"
        fi
        "$XSETROOT" -cursor_name left_ptr -solid "$BACKCOLOR"
fi


SESSREG=`gdmwhich sessreg`
if [ "x$SESSREG" != "x" ] ; then
        # some output for easy debugging
        echo "$0: Registering your session with wtmp and utmp"
        echo "$0: running: $SESSREG -a -w /var/log/wtmp -u /var/run/utmp -x \"$X_SERVERS\" -h \"$REMOTE_HOST\" -l \"$DISPLAY$
        exec "$SESSREG" -a -w /var/log/wtmp -u /var/run/utmp -x "$X_SERVERS" -h "$REMOTE_HOST" -l "$DISPLAY" "$USER"
        # this is not reached
fi

# some output for easy debugging
echo "$0: could not find the sessreg utility, cannot update wtmp and utmp"
exit 0

Warning: if you put the -f into the command, you'll get a script that doesn't stop and let gnome finish loading!

Wrapup

Now that you have synergy installed and running, you can copy and paste between machines and also just have all out fun with the keyboard and mouse on both/or more machines. I use Synergy all the time, that way I can write in one window and talk/chat/read mail in another window. It makes using multiple computers a lot easier and a lot more fun.

CategoryDocumentation