Setting up Synergy for little hassle

12 Sep 2009

I tend to use my Mac Laptop at work a lot and that has spilled over into using it at home quite often as well. I got tired of having to switch from the keyboard and mouse of my desktop over to the laptop’s keyboard and mouse over and over when I needed to do something on it.

My Coworker at work has a similar setup and told me to try Synergy so I thought I would give it a shot. Essentially Synergy allows you to connect expand screens of any computers onto a single computer.

For example

I put my laptop to the left of my screens at home and want to be able to use the keyboard and mouse from my main computer on my laptop.

Here you can see my dual monitors with my laptop to the left of them

Here you can see my dual monitors with my laptop to the left of them

So setting up synergy I can now do this.

Before we start, do note that synergy can run on virtually any Operating System(Windows, Mac, Linux, Unix) which is super nice

Server Setup

I’ll go over the Linux & Windows setup as those are the only two that I have done

Windows


Install Server

Go here and download the newest .exe file and run it(The install is trivial, so I’m not going to post directions for it)

Setup Server

Create Config File

Create a file called synergy.sgc and place it inside your My Documents or Documents path depending on if you have XP or Vista/7

section: screens

:

switchCorners = none

switchCornerSize = 0

:

switchCorners = none

switchCornerSize = 0

end

section: links

:

left =

:

right =

end

section: options

end

You will need to replace and with the output of the command hostname(run from a terminal or command window in windows) on the client and server

Not sure why, but wordpress doesn’t want to indent inside a blockquote so that file looks a bit messy, sorry.

Setup Autostart for Synergy

Create a file called SynergyAutostart.reg and place the following code into that file

[HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun]

“Synergy Server”=””C:Program Files (x86)Synergysynergys.exe”  –no-daemon –debug WARNING –name llandru –address :24800″

You will probably need to change the path to the actualy location of the synergys.exe file unless you are using 64bit Vista or 7

Insert registry entry

Simply double click the SynergyAutostart.reg file and it should prompt you if you want to insert something into your registry. Go ahead and click next and ok on whatever comes up

Test to see if it works

Now to make sure that the server is setup, open the start menu and find Synergy and run the server

It should have all the correct options specified so click Test, it should open a log file and run synergy. You can parse the dialogues that come up and determine if its working, the real test will be after the client is setup

You can Quit the app now

Linux


Install Server

I’m not going to really bother too much about the install. Frankly, if you are using Linux, you know how to install it

You can use the link from the windows section if you want the source or an rpm, otherwise use apt-get or whatever

Setup Server

Create Config File

Create a file called .synergy.conf in your home directory with the same contents as the windows file replaceing and in the same manner

Test to see if it works

In a terminal issue synergys -f

It should spit a bunch of stuff to the screen. Like the Windows instructions, parse it and just check to see if it looks right

Client Setup

Install Client

Because I’ve only setup the client on a Mac, those are the only instructions I’m going to post

The easiest way to get Synergy in my opinion for the mac is to download the Mac Version from here

Untar and decompress the download wherever

Copy/link/move synergyc to /usr/sbin that way you can just call synergyc from the command line without a path


Test Client and Server

Ok, this is pretty much what we are after. Will it work or not

Execute the server either from the Windows GUI or Linux command line(just do it the same way you tested from the above steps in the install instructions)

On the client open a terminal and issue synergyc -f

If your cursor moves to the center of the screen that’s an indication that its probably working. To know for sure just move the mouse on your Server over to the left and see if it move onto your client. If it does that means it worked, if it doesn’t you will want to check the server and client’s output for reasons why.

If it works now you are set. You can check out SynergyKM for Mac for a gui version to make this easier, or QuickSynergy for Linux

If your feeling randy you can continue reading to find out how to use a script I wrote to run the client so it connects securely.

Extra L33t Script Instructions

    • *I wanted a way to simply execute the client and have it determine if my laptop was at home or at work and connect accordingly. At home I don’t require encryption on the connection from the client and server. At work I prefer it as you are sending raw keystrokes over the air for nasty people to nab and capture your passwords and emails about how you hate your boss, haha.</p>

So I present you the script

#!/bin/bash

# Your home server’s ip

homeserver=””

# Your work server’s ip

workserver=””

# Does en0(wired) have link

en0=`ifconfig en0 | grep ‘media:’ | egrep -o ‘active|inactive’`

# Does en1(wireless) have link

en1=`ifconfig en1 | grep ‘media: autoselect status:’ | egrep -o ‘active|inactive’`

# If the wired connection has link use it

if [ “${en0}” = “active” ]

then

interface=”en0″

# If the wireless connection has link use it

elif [ “${en1}” = “active” ]

then

interface=”en1″

# Otherwise exit and print an error

else

echo “No interfaces appear to have link”

exit -1

fi

# Determine the ip address of your machine

ip=`ifconfig ${interface} | egrep -o ‘inet ([0-9]{1,3}.){3}[0-9]{1,3}’ | egrep -o ‘([0-9]{1,3}.){3}[0-9]{1,3}’`

server=””

# Make sure no other synergy clients are running already

killall synergyc

# Is your ip a home ip(I think 192 is standard enough to assume for home NAT)

echo ${ip} grep -q 192

# If the last command exited with a 0 then use

if [ $? -eq 0 ]

then

server=${homeserver}

else

server=”localhost”

ssh -f -C -L 24800:${workserver}:24800 ${workserver} “killall synergys; synergys -f”

fi

nohup synergyc -f ${server} &

exit 0

So basically this script determins if you are at home or at work and then connects to the server. If it determins you are at work it will connect to the server via ssh and actually execute the server for you and then connect the client to it.

Things you will need to do

  • Put that into a file in your home directory on your client Mac. The file is best if you append .command to the end so you can double click it
  • You will need to chmod 755 the file to make it executable
  • You need to change homeserver and workserver to the ip addresses of the computers
  • You will probably want to create an ssh key to auto log you in through ssh so you don’t have to enter in a password to connect the client

Well there you go.

Questions and Comments can be posted here and I’ll respond

«« Previous Post Next Post »»