Linux and Windows with the same keyboard and mouse

I have recently refurbished an old computer I had at my parents place and decided it was time to have my first Linux physical machine and not just a virtual machine. However, I had to solve the problem of having only a single keyboard and mouse at home and avoid the hassle of unplugging and connecting the peripherals every time I want to work in Linux.

Luckily, a friend recommended me barrier (shout out to Víctor), so I took the challenge to set it up at home. My desk at home consists of:

  • A Windows 10 Laptop
  • An Ubuntu Jammy (22.04) PC
  • Two screens
  • One mouse
  • One keyboard

After reading barrier’s documentation it became clear that it has a server-client architecture. Since I mainly work with my laptop, I chose to make this the server and make the Linux PC the client. This also meant that I had to configure both machines to have static IPs. I checked my router configuration:

  • Network range: 192.168.1.0/24
  • DHCP range: 192.168.1.125-192.168.1.254
  • Gateway: 192.168.1.1

Good, no need to change the router to make some IPs available, part of the network range is not covered by DHCP. I configured both machines as follows:

  • Laptop (the server): 192.168.1.10
  • Ubuntu (the client): 192.168.1.11

I installed the last available version of barrier on both systems. Luckily, barrier provides a .exe on its release page on Github: https://github.com/debauchee/barrier/releases/tag/v2.4.0, so that covers Windows. As for Ubuntu, as easy as:

sudo apt update
sudo apt install barrier

Now that barrier is installed on both machines, it is time to configure it.

Windows

When barrier is started for the first time, it let’s you choose between server an client. I chose server. On the main panel of barrier the preferred settings are selected by default. All I had to do was making sure that the Server dialog box was selected.

server-config-1

Then, after clicking on the Configure Server button, the following window pops up:

server-config-2

I double clicked on the right of my main display, as I wanted to have Ubuntu displayed on my screen on the right, and named this client with the same hostname my Ubuntu machine has: workstation. Once this is done, and the barrier server is up and running, we are done with Windows.

Linux

For Linux, I wanted to make the client start as a system service. Easiest way to set this up is to manually configure barrier, test it works and then save the command in a service file. In my case:

client-config-1

$ ps aux | grep barrierc
user   12128  2.5  0.0  96128  7840 ?        Sl   23:20   0:03 /usr/bin/barrierc -f --no-tray --debug INFO --name workstation --disable-crypto --log /var/log/barrier.log [192.168.1.10]:24800
user   12486  0.0  0.0  17868  2540 pts/5    S+   23:23   0:00 grep --color=auto barrierc

Notice the flag --disable-crypto. For simplicity purposes, I disabled SSL as I have separate WIFI network for guests ;)

I checked as well the command line options listed here, and added --restart to the service definition.

I created the systemd service definition:

$ sudo vim /etc/systemd/system/barrier.service
$ cat /etc/systemd/system/barrier.service
[Unit]
Description=Barrier mouse/keyboard share
Requires=display-manager.service
After=display-manager.service
StartLimitIntervalSec=0

[Service]
Type=simple
ExecStart=/usr/bin/barrierc -f --no-tray --debug INFO --name workstation --disable-crypto --restart --log /var/log/barrier.log [192.168.1.10]:24800
Restart=always
RestartSec=1

[Install]
WantedBy=multi-user.target

And configured it so it boots on startup:

sudo systemctl daemon-reload
sudo systemctl enable barrier
sudo systemctl start barrier

And that’s it, setup done.

Result

:)

result

Updated: