<p>In today's show we will talk about installing synergy so that you can
control the keyboard and mouse of another computer securely over
ssh.</p>
<p>Install synergy on both computers as root</p>
<pre><code># dnf install synergy
# apt install synergy</code></pre>
<p>The main pc is <code>pc_middle</code> and it is the one with the
keyboard and mouse we intend to use for all the computers.</p>
<p>The only other pc in this configuration is, one on the right which we
call <code>pc_right</code></p>
<p>On <code>pc_middle</code> create a configuration file. I put it in
<code>~/etc/synergy-work.conf</code></p>
<pre><code>section: screens
    pc_middle:
    pc_right:
end

section: links
pc_middle:
    right = pc_right
pc_right:
    left  = pc_middle
end</code></pre>
<p>On <code>pc_middle</code> add entry to <code>~/.ssh/config</code> to
allow portforwarding back, for the <strong>synergy</strong> port
<em>24800</em></p>
<pre><code>Host pc_right
    Hostname 192.168.0.150
    RemoteForward 127.0.0.1:24800 127.0.0.1:24800 # send back from the client to me</code></pre>
<p>On <code>pc_middle</code> run synergy server in the foreground with
debug enabled</p>
<pre><code>[user@pc_middle ~]$ synergys --debug DEBUG --no-daemon --server --address 127.0.0.1 --config ~/etc/synergy-work.conf --name pc_middle --log /tmp/synergy-work.conf.log
[2022-12-03T16:29:05] DEBUG: opening configuration &quot;~/etc/synergy-work.conf&quot;
[2022-12-03T16:29:05] DEBUG: configuration read successfully
[2022-12-03T16:29:05] DEBUG: XOpenDisplay(&quot;:0&quot;)
[2022-12-03T16:29:05] DEBUG: xscreensaver window: 0x00c00001
[2022-12-03T16:29:05] DEBUG: screen shape: 0,0 5760x2160 (xinerama)
[2022-12-03T16:29:05] DEBUG: window is 0x05e00004
[2022-12-03T16:29:05] DEBUG: adopting new buffer
[2022-12-03T16:29:05] DEBUG: opened display
[2022-12-03T16:29:05] WARNING: LANGUAGE_DEBUG Poll result 0
[2022-12-03T16:29:05] DEBUG: registered hotkey ScrollLock (id=ef14 mask=0000) as id=1
[2022-12-03T16:29:05] NOTE: started server, waiting for clients
[2022-12-03T16:29:05] DEBUG: event queue is ready
[2022-12-03T16:29:05] DEBUG: add pending events to buffer
[2022-12-03T16:29:05] DEBUG: screen &quot;pc_middle&quot; shape changed</code></pre>
<p>On <code>pc_middle</code> you can check that it's running</p>
<pre><code>[user@pc_middle ~]$ netstat -anp | grep 24800
tcp        0      0 127.0.0.1:24800     0.0.0.0:*               LISTEN      90859/synergys</code></pre>
<p>On <code>pc_middle</code> you can connect to
<code>pc_right</code></p>
<pre><code>[user@pc_middle ~]$ ssh pc_right
user@pc_right:~$</code></pre>
<p>On <code>pc_right</code> (either on its own keyboard, or via ssh
session from <code>pc_middle</code>), check that port <code>24800</code>
is listening</p>
<pre><code>user@pc_right:~$ netstat -anp | grep 24800
tcp        0      0 127.0.0.1:24800         0.0.0.0:*               LISTEN</code></pre>
<p>On the other keyboard that is connected to the <code>pc_right</code>
(see note below &#x2020;)</p>
<pre><code>user@pc_right:~$ synergyc --debug INFO --no-daemon --name pc_right 127.0.0.1
[2022-12-03T16:38:59] NOTE: started client
        /build/synergy-3N7yN5/synergy-1.8.8-stable+dfsg.1/src/lib/synergy/ClientApp.cpp,404
[2022-12-03T16:38:59] NOTE: connecting to &#39;127.0.0.1&#39;: 127.0.0.1:24800
        /build/synergy-3N7yN5/synergy-1.8.8-stable+dfsg.1/src/lib/client/Client.cpp,146
[2022-12-03T16:38:59] NOTE: connected to server
        /build/synergy-3N7yN5/synergy-1.8.8-stable+dfsg.1/src/lib/synergy/ClientApp.cpp,294</code></pre>
<p>Back on <code>pc_middle</code>, you should see the the log that you
have connected</p>
<pre><code>[2022-12-03T16:40:15] DEBUG: Opening new socket: 18FC73A0
[2022-12-03T16:40:15] NOTE: accepted client connection
[2022-12-03T16:40:16] DEBUG: received client &quot;pc_right&quot; info shape=0,0 5760x2160 at 2787,1371
[2022-12-03T16:40:16] NOTE: client &quot;pc_right&quot; has connected</code></pre>
<p>&#x2020; Note: If you tried to run the client <code>synergyc</code> over the
ssh connection on <code>pc_middle</code> it will connect, but the mouse
will never <em>move</em> to the other screen.</p>
<p>Now from the <code>pc_middle</code>, you should be able to
<em>move</em> the mouse over to the <code>pc_right</code> screen.</p>
<p>Now using the keyboard and mouse on the <code>pc_middle</code>, you
should now be able to move the mouse and type on the
<code>pc_right</code> screen.</p>
<p>The logs on the <code>pc_middle</code>, should show you information
about switching from one computer to the other.</p>
<pre><code>[2022-12-03T17:05:18] INFO: switch from &quot;pc_middle&quot; to &quot;pc_right&quot; at 0,225
[2022-12-03T17:05:18] INFO: leaving screen
[2022-12-03T17:05:18] WARNING: LANGUAGE_DEBUG Poll result 0
[2022-12-03T17:05:18] DEBUG: open clipboard 0
[2022-12-03T17:05:18] DEBUG: ICCCM fill clipboard 0
[2022-12-03T17:05:18] DEBUG:   available targets: text/plain (654), UTF8_STRING (445), STRING (31), TEXT (444)
[2022-12-03T17:05:18] DEBUG: added format 0 for target UTF8_STRING (445) (8 bytes)
[2022-12-03T17:05:18] DEBUG: close clipboard 0
[2022-12-03T17:05:18] INFO: screen &quot;pc_middle&quot; updated clipboard 0
[2022-12-03T17:05:18] DEBUG: open clipboard 1
[2022-12-03T17:05:18] DEBUG: ICCCM fill clipboard 1
[2022-12-03T17:05:18] DEBUG:   available targets: text/plain (654), UTF8_STRING (445), STRING (31), TEXT (444), text/html (653)
[2022-12-03T17:05:18] DEBUG: added format 1 for target text/html (653) (113 bytes)
[2022-12-03T17:05:18] DEBUG: added format 0 for target UTF8_STRING (445) (5 bytes)
[2022-12-03T17:05:18] DEBUG: close clipboard 1
[2022-12-03T17:05:18] INFO: screen &quot;pc_middle&quot; updated clipboard 1
[2022-12-03T17:05:18] DEBUG: sending clipboard 0 to &quot;pc_right&quot;
[2022-12-03T17:05:18] DEBUG: sent clipboard size=20
[2022-12-03T17:05:18] DEBUG: sending clipboard 1 to &quot;pc_right&quot;
[2022-12-03T17:05:18] DEBUG: sent clipboard size=138
[2022-12-03T17:05:19] INFO: switch from &quot;pc_right&quot; to &quot;pc_middle&quot; at 5757,583
[2022-12-03T17:05:19] INFO: entering screen
[2022-12-03T17:05:19] DEBUG: send xscreensaver command: 582 0 0</code></pre>
<p>Back on <code>pc_right</code> you can close the client by holding
Control and pressing C, or Ctrl+C for short.</p>
<p>The logs on the <code>pc_middle</code>, should show you that the
client disconnected.</p>
<pre><code>[2022-12-03T16:40:18] NOTE: client &quot;pc_right&quot; has disconnected
[2022-12-03T16:40:18] DEBUG: Closing socket: 18FC73A0</code></pre>
<p>As we are running over ssh, there is no need to configure
<code>--enable-crypto</code> but you can if you wish.</p>
<p>Now that everything is working correctly you can make it easier to
start.</p>
<p>As we saw before (&#x2020;) the client needs to be run from the physical X
Session that you see on the second computer.</p>
<p>On <code>pc_right</code> create a new bash script file eg:
<code>nano ~/bin/start-synergy-client.bash</code></p>
<pre><code>#!/bin/bash
killall synergyc
sleep 2
synergyc --name pc_right 127.0.0.1
exit 0</code></pre>
<p>Still on <code>pc_right</code> allow the file to be executable
<code>chmod +x ~/bin/start-synergy-client.bash</code></p>
<p>Still on <code>pc_right</code> and <strong>in the session you wish to
control</strong>, run <code>start-synergy-client.bash</code></p>
<p>I find it easiest to just run this in a shell once I login on
<code>pc_right</code>, but you could configure it to <a
href="https://learn.adafruit.com/synergy-on-raspberry-pi/setup-synergy-client-autostart">run
automatically once you log in</a>.</p>
<p>Back on <code>pc_middle</code>, create a new bash script file eg:
<code>nano ~/bin/start-synergy-server.bash</code></p>
<pre><code>#!/bin/bash
server_name=synergys # may also be synergy-core
killall &quot;${server_name}&quot;
${server_name} --server --address 127.0.0.1 --config ~/etc/synergy-work.conf --name pc_middle --log /tmp/synergy-work.conf.log
setxkbmap -option &quot;compose:ralt&quot;
setxkbmap -option &quot;ctrl:nocaps&quot;
ssh pc_right</code></pre>
<p>Still on <code>pc_middle</code> allow the file to be executable
<code>chmod +x ~/bin/start-synergy-server.bash</code></p>
<p>Still on <code>pc_middle</code> you can run the command
<code>start-synergy-server.bash</code> and it will open a ssh shell to
<code>pc_right</code>.</p>
<p>Over that connection <code>pc_right</code> can send back commands to
the server.</p>
<p>A side note about the special address 127.0.0.1.</p>
<p>It's often referred to as <strong>loopback</strong>, home, or
<code>localhost</code> and is usually defined in
<code>/etc/hosts</code></p>
<p>The address is used by programs running on a given computer to
communicate with other programs running on the same computer.</p>
<p><a
href="https://en.wikipedia.org/wiki/Localhost">https://en.wikipedia.org/wiki/Localhost</a></p>
<blockquote>
<p>IPv4 network standards reserve the entire address block 127.0.0.0/8
(more than 16 million addresses) for loopback purposes.</p>
</blockquote>
<p>If you are confused, then just think of it like you when your boss
says "I'm going home now, you should also go home."</p>
<p>It's clear that they mean "I'm going to <strong>my</strong> home now,
and you should also go to <strong>your</strong> home."</p>
<p>So the address 127.0.0.1 on <code>pc_middle</code> is only available
on <code>pc_middle</code>, and equally the address 127.0.0.1 on
<code>pc_right</code> is only available on <code>pc_right</code>.</p>
<p>The server is listening on its loopback address 127.0.0.1 on
<code>pc_middle</code>, while the client is listening on its loopback
address 127.0.0.1 on <code>pc_right</code></p>
<p>It is the <code>RemoteForward</code> configuration that creates a ssh
<code>tunnel</code> that is doing the heavy lifting.</p>
<pre><code>RemoteForward 127.0.0.1:24800 127.0.0.1:24800</code></pre>
<p>It tells the Remote (in this case <code>pc_right</code> ) to listen
to the port <code>24800</code> its loopback address.</p>
<p>This is where the client on <code>pc_right</code> will be talking
to.</p>
<p>The ssh connection will then Forward any packets back to the other
side (in this case <code>pc_middle</code> )</p>
<p>And to send to the port <code>24800</code> its loopback address.</p>
<p>And on that address the server is listening.</p>
