Synergy share keyboard and mouse from Freebsd to Mac or any other OS

Synergy lets you share your keyboard and mouse between multiple computers
and works on Windows, macOS, Linux, and Raspberry Pi.

A lot of Freebsd users use Macs because of the unix underpinnings,
despite the fact the mac ships with a version of bash from 2007
because later version of bash use gpl 3 which Apple wont use

The free version of synergy on the mac doesnt support ssl encryption,
you need to buy the pro version of sysnergy on the mac to enable ssl

In this how to guide i will install synergy on freebsd and mac os,
to enable keyboard and mouse sharing between the 2 operating systems

Installing synergy on Freebsd

Bash:
# pkg install synergy

Edit the synergy config file

Bash:
doas vi /usr/local/etc/synergy.conf

Create a simple configuration of two computers side by side

where freebsd is the name of the freebsd machine to the left of the mac
and mac.local is the hostname of the mac

Bash:
# sample synergy configuration file
section: screens
    freebsd:
    mac.local:
end

section: links
    freebsd:
        right = mac.local

    mac.local:
        left  = freebsd
end

section: options
    keystroke(super+`) = switchInDirection(right)
    keystroke(super+shift+`) = switchInDirection(left)
end

We also enable 2 keyboard shortcut which let us switch screens
I am using the i3wm window manager and have the alt key defined as the super key

So pressing alt ` will move the cursor from the left screen to the right screen,
and pressing alt shift ` when on the right will move the cursor back to the left screen

Mac synergy set up

We will install the homebrew package manager on Mac OS to install synergy,
this will install the synergy gui application that also has a menulet that sits in the mac menu bar to easily start and stop synergy

To install the homebrew package manager on the mac we first need to install the xcode command line tools

Open a terminal and enter the following code

Bash:
xcode-select --install

You will be prompted for you admin password and then the xcode command line tools will be downloaded and installed

Now we can install the homebrew package manager
Open a terminal and enter the following code to install homebrew

Bash:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Run the following command once you’re done to ensure Homebrew is installed and working properly:

Bash:
brew doctor

You can use homebrew to install either command line programs or gui applications
We will create a Application folder in our Home folder to install synergy,
as i prefer to keep user installed programs separate from the preinstalled Apple Applications in /Applications

This will install synergy for just our user on the Mac,
if you have multiple users on the Mac and you want to let them use synergy then install synergy in /Applications

Open the terminal and enter the following code to create a Applications directory in your Home

Bash:
mkdir -p ~/Applications

Now we will use homebrew to install synergy
To install synergy into the /Applications folder for multiple user on the Mac we use this command

Bash:
brew cask install synergy

To install synergy into the ~/Applications folder for just our user we use this command

Bash:
brew cask install --appdir="~/Applications" synergy

Before we can use synergy to share our keyboard and mouse
we need to make sure the computers can connect to each other over the network,
create a firewall rule on Freebsd to open the port used by synergy and then start the server and client

Editing the hosts file

We will edit the /etc/hosts files on Freebsd and Mac and enter the ip address and name of the other computer

* Freebsd hosts file

edit the /etc/hosts file on Freebsd

Bash:
# vi /etc/hosts

enter the ip address and hostname of the mac

Bash:
192.168.1.101 mac.local mac

replace 192.168.1.101 with the ip address of your mac

replace mac.local and mac with your macs computer name,
which can be found by opening the system preferences sharing tab

* Mac hosts file

edit the mac /etc/hosts file

Bash:
sudo vim /etc/hosts

and add the ip address and name of the Freebsd computer

Bash:
192.168.1.3 freebsd

replace 192.168.1.3 with the ip address of your Freebsd computer
and replace freebsd with your freebsd computers host name


Testing the connection with ping


Now we have entered the hostname and ip addresses in the hosts files we can use ping to test the connection

On the Freebsd machine we will try pinging the hostname of the mac that we added to our /etc/hosts file

Bash:
ping -c 3 mac

On the Mac we will try pinging the hostname of the Freebsd that we added to our /etc/hosts file

Bash:
ping -c 3 freebsd

Opening port 24800 for synergy on the Freebsd firewall


Next we need to open tcp port 24800 on the Freebsd firewall for the synergy server

Bash:
# vi /etc/pf.conf

Below is an example pf.conf file for synergy
change int_if="ue0" to the name of your network interface which can be found with ifconfig


Bash:
int_if="ue0" # internal network interface
tcp_services = "{ 24800 }" # tcp services - rtorrent, syncthing, synergy
udp_services = "{  }" # udp services - rtorrent, syncthing
icmp_types = "{ echoreq, unreach }"
tcp_state="flags S/SA keep state"
udp_state="keep state"

set block-policy drop
set loginterface $int_if
set fingerprints "/etc/pf.os"
set skip on lo0
scrub in all fragment reassemble no-df max-mss 1440
antispoof log quick for { lo $int_if } label "block_spoofing"

block log all # block log all
block return out quick inet6 all tag IPV6 # block ipv6
block in quick inet6 all tag IPV6 # block ipv6

# icmp
pass inet proto icmp all icmp-type $icmp_types keep state tag ICMP

# Allow the tcp and udp services defined in the macros at the top of the file
pass in on $int_if inet proto tcp from any to ($int_if) port $tcp_services $tcp_state tag TCP_IN
pass in on $int_if inet proto udp from any to ($int_if) port $udp_services $udp_state tag UDP_IN

# outbound traffic
block out on $int_if all
pass out quick on $int_if all modulate state

edit the /etc/rc.conf

Bash:
# vi /etc/rc.conf

enable the pf firewall by adding the code below

Bash:
pf_enable="YES"

reload the pf firewall

Bash:
# pfctl -f /etc/pf.conf

Starting the synergy server

The computer whose keyboard and mouse you are sharing is called the server,
so in this case freebsd will be the synergy server and the mac will be the synergy client

Start the synergy server using the synergy-core --server command
with the --config option and the location of the synergy.conf config file

Bash:
synergy-core --server --config /usr/local/etc/synergy.conf

You can stop the synergy server using the pkill command

Bash:
pkill synergy-core

I have written a simple shell script to to start the synergy server and use pkill to stop it

Save the code below in a text file called synserver or choose whatever name you like for the script

Bash:
#!/bin/sh

# synergy-core server
usage="usage: $(basename "$0") [ start | stop ]"

# check if 1 argument is passed to the script
[ $# = 1 ] || { printf "%s\n" "$usage"; exit 1; }

# case statement
input="$1"
case "$input" in
  start)
        # if server isnt running start it
        synergy-core --server --config /usr/local/etc/synergy.conf
        break;;
  stop)
        # if server is running stop it
        pkill synergy-core
        break;;
  *)    printf "%s\n" "$usage";;
esac

If you dont have a bin directory in your home then create it

Bash:
mkdir -p ~/bin

move the synserver script into the ~/bin directory

Bash:
mv synserver ~/bin

then make it executable

Bash:
chmod +x ~/bin/synserver

add the ~/bin directory to our path

edit your ~/.bashrc if you are using bash

Bash:
vi ~/.bashrc

or you ~/.zshrc if you are using zsh

Bash:
vi ~/.zshrc

and add the following code to add the ~/bin directory to your path

Bash:
# home bin
if [ -d "$HOME/bin" ]; then
   PATH="$HOME/bin:$PATH"
fi

source your ~/.bashrc to pick up the changes

Bash:
source ~/.bashrc

or if you are using zsh source your ~/.zhsrc file

Bash:
source ~/.zshrc

You can now run the synserver script which accepts two arguments start or stop

for example to use the synserver script to start the synergy-core server

Bash:
synserver start

and to stop the server

Bash:
synserver stop

Starting the synergy client

The mac will be the synergy client and connect to the synergy server running on freebsd,
and allow you to share the freebsd mouse and keyboard to the mac

Right click on the synergy.app Application and select open and click ok,
when you first open synergy you will be prompted to allow Accessibility access to the keyboard and mouse
which is in the System Preferences, Security & Privacy, Privacy tab in the left column there is a item called Accessibility

If you select the Accessibility in the left column you will see Synergy listed in the right pane under the heading
Allow the apps below to control your computer.

Click the lock in the bottom left of the window and enter you admin password to allow you to make changes
then select the Synergy icon in the right pane and click the checkbox to allow synergy to control your mac

synergy-accessibilty.png


We need to make sure to allow incoming connections to the synergy application in the mac firewall,
in the Security & Privacy section of System Preferences select the Firewall tab

Then click the Firewall Options.. button,
if its greyed out click the lock at the bottom right of the window and enter your admin password

In the new window you should see the Synergy.app listed with a green icon and Allow incoming connections,
if the Synergy.app isnt listed press the plus button and select the Synergy.app and then select Allow incoming connections and close the window

6347


It is also possible to add Synergy as a login item on the mac so that it starts automatically and connects to the synergy server
Open the System Preferences, Users & Groups section and then select your user name in the left column,
in the right pane of the window select the Login Items tab, then click the plus icon and select the Synergy.app in the Finder window

Make sure the synergy server is started on the Freebsd machine,
on the mac open the Synergy.app or click the menu icon if its already running and select show to open the synergy configuration window

In the Synergy configuration window we need use the client section at the bottom of the window,
to connect to the synergy sever running on freebsd

In the text box next to Server:
add the hostname of the freebsd machine running the synergy server which you added to /etc/hosts on the mac

Click the checkbox next to
Client (use another computer's mouse and keyboard):

Then click the apply button and then the start button to start the synergy client on the mac to connect to the synergy server running on freebsd

6348


Using synergy


Try moving the cursor on your freebsd machine running the synergy server to the right of the screen,
it should appear on the left hand side of your mac's screen, then move the cursor back to the left and it should reappear on you freebsd screen

In the /usr/local/etc/synergy.conf file on freebsd we defined 2 keyboard shortcuts
which switches the cursor from freebsd screen to the mac and back again rather than having to move the cursor to the edge of the screen

By pressing alt ` on freebsd the cursor will switch to the macs screen on the right
and pressing shift alt ` on the mac will switch the cursor back to freebsd again
 
Back
Top