Sounds like a line from a certain â€œpointy-haired boss,â€ doesnâ€™t it?
I use a MacBook Pro running OS X Leopard as my main system at the office. I have a secondary display connected to it and I use the built-in â€œSpacesâ€ feature. My secondary system, a desktop, is running Ubuntu 8.10 workstation. For several months now, I have had two keyboards and mice to deal with. There had to be a way to share one keyboard and mouse between the two systems.
Enter the utility, Synergy.
From the Synergy website:
â€œSynergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems, each with its own display, without special hardware. It’s intended for users with multiple computers on their desk since each system uses its own monitor(s).
Redirecting the mouse and keyboard is as simple as moving the mouse off the edge of your screen. Synergy also merges the clipboards of all the systems into one, allowing cut-and-paste between systems. Furthermore, it synchronizes screen savers so they all start and stop together and, if screen locking is enabled, only one screen requires a password to unlock them all.â€
This is exactly what the doctor ordered. What I found, however, is that it is not a simple as clicking â€œNext -> Next -> Finish.â€ To get this working on Linux and OS X, a person has to get their hands a bit dirty.
In the most basic sense, Synergy works by running a server program on the system that has the keyboard and mouse that you want to use, and a client program on the computer that you want to control. On â€˜nix based systems, which includes the Mac, this is all done through a terminal interface. There is no slick GUI. (I did notice that there are some projects out there that are working on a GUI, but none looked mature enough at the time of this writing.)
Using a MacBook Pro laptop as the server throws a wrench in the works as well. I need to grab the laptop and take it with me to meetings and when I leave at night. I donâ€™t want to leave the Synergy programs running when Iâ€™m not at my desk. If I want to start and stop the program on both systems every time the Mac comes and goes from my desk, it is a manual process that has to be done from the keyboard and mouse physically connected to each system.
Big Pain. I want to click on something on the Mac that will start or stop the programs running on both the Mac and the Linux workstation. I did find a way to make this work. I wonâ€™t go into detail on the basic set up of Synergy on each platform, as that is covered on their website. I will outline what I did to make this work the way I wanted it to on both the Mac and the Linux system.
The first thing to take note of is a bug in the way the Synergy server runs on OS X. Usually, when you execute the synergys program, it launches and runs as a background process. On OS X Leopard, you get an error and the program stops. You can, launch it with the -f option that forces the process to continue running in the foreground. The bad thing about this is that you need to keep the terminal window open while synergy is running.
To get Synergy to run as a background process, I used the screen command to execute it. This command will let you detach a process from the terminal. That means, you can kick off synergys with the -f option and it will become a background process. More on this in a bit.
The next big hurdle is remotely executing the start and stop scripts on the Linux system. By using some SSH tools, I added a public encryption key to my profile on the Linux system. This prevents me from keying a password when I make an SSH connection to the Linux system. Having already created the scripts on the Linux workstation, all I had to do was use an SSH statement in my shell script to execute the remote script and start the Synergy client.
First, run ssh-keygen on the Mac to generate your key pair. There will be a public and a private key. After that, the public key needs to be distributed to the remote system. OpenSSH includes a shell script called ssh-copy-id that will do this for you. Unfortunately, OS X doesnâ€™t have that script, so you can use this one instead:
if [ ! -f ~/.ssh/id_dsa.pub ];then
echo â€œprivate key not found at $KEYâ€
echo â€œ* please create it with â€œssh-keygen -t dsaâ€ *â€
echo â€œ* to login to the remote host without a password, donâ€™t give the key you create with ssh-keygen a password! *â€
if [ -z $1 ];then
echo â€œPlease specify firstname.lastname@example.org as the first switch to this scriptâ€
echo â€œPutting your key on $1… â€œ
ssh -q $1 â€œmkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo â€œ$KEYCODEâ€ >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keysâ€
I found that script here.
Save it as ssh-copy-id and make it executable. Then execute it like this:
You will be prompted for your password this time, so that the key can be copied. Now test this by issuing the following command:
If you werenâ€™t prompted for your password, you win!
I decided that the best way to handle all this process starting and stopping is with a shell script. I already have an Automator script that connects my Mac to some network shares and sets the volume to an office-friendly level. In addition, I have an Automator script that reverses that process when I leave at night. By creating shell scripts for Synergy and adding them to my existing Automator scripts, things will be much easier.
Here is my script with server and user names removed:
# Script to start Synergy on remote linux system and local system
screen -d -m /Applications/synergy-1.3.1/synergys -f –config /Applications/synergy-1.3.1/synergy.conf -f
ssh userid@servername /home/userid/scripts/startsynergy
The first line of that script launches the local Synergy server process. The second line launches the remote script through SSH.
There is the script I use to stop Synergy:
# Script to stop Synergy on ubuntu01blea and local system
ssh userid@servername /home/userid/scripts/stopsynergy
You can test these scripts in a terminal window.
Now, to add this shell script to Automator, select â€œUtilitiesâ€ and then â€œRun Shell Scriptâ€.
Type the full path to your script in the properties of that object.
Add any other items you want to your Automator script and save it.
Thatâ€™s it! Youâ€™re done!
I’ve been in IT for over 25 years.Â As a result, I drink way too much coffee, my eye occasionally twitches, and no I will not fix your computer.Â I’m also a photographer, videographer, and an elder at my church.
Did I mention I like coffee?