Share your keyboard and mouse between computers with Barrier

Declutter your desk by sharing your mouse and keyboard across multiple computers at once, including your Raspberry Pis, with Barrier. Raspberry Pi Director of Software Engineering, Gordon Hollingworth, shows you how.

Barrier walkthrough

Subscribe to our YouTube channel: http://rpf.io/ytsub Help us reach a wider audience by translating our video content: http://rpf.io/yttranslate Buy a Raspbe…

Desk clutter is a given

My desk is a bit untidy. Talking to people in our office, you’ll find that it’s mostly because I only clear it properly once a year, or leave it entirely until the next time we move office!

It’s cluttered with Raspberry Pis of random types, with little tags saying what’s wrong or right about each one, and then there’s every manner of SD card, adapter, JTAG connector, headphones, and whiteboard marker pens you can dream of filling the gaps.

But one thing that really annoys me is that I tend to have a mouse and keyboard per computer, and I’ve got at least four computers running at my desk at any one time.

Solutions to this problem have existed for a very long time, known as KVM (keyboard, video and mouse) switches; many people use these to switch (literally with a big toggle switch) between computer 1, 2, and 3 while using a single screen.

But if that’s what you want to do, the best solution is to use VNC on each of the computers so you can use a single display, keyboard, and mouse to access each of their screens and bring them all together.

And, that’s okay, but…

But that’s not quite what I want: I like having the mass-screen real-estate around me, and I like just glancing to the left to see my Raspberry Pi on its own screen.

If only there was a way to share my mouse and keyboard across multiple computers without having to flick switches or unplug USBs.

Well…

Barrier to the rescue!

In the same way one may set up multiple monitors for one computer, and move the mouse cursor seamlessly between them, Barrier allows you to share peripherals between multiple computers, allowing you to host your keyboard and mouse on one computer. It lets you simply drag your cursor from screen to screen, from device to device, as if by magic.

Download and set up Barrier

Barrier is free to use, and simple to set up. You can either follow the video tutorial shared above, or continue reading below:

Download barrier to your main computer

First, download and install Barrier from the developers’ installation page: github.com/debauchee/barrier/releases

At the end of the installation, the application will run. Select the Server option (the server is the one that has the keyboard and mouse that you want to share).

Next select Configure Server. Click on the computer screen in the top-right and drag it to where you want it to appear in relation to the server. It will default to being called ‘Unnamed’.

Next, double-click the new ‘Unnamed’ screen to set it up.

The only thing you need to do here is to set the screen name. Here I’ve changed it to ‘raspberrypi’.  Click OK here and on the Server configuration‘ dialogue. You’ll return to the main Barrier page. Click Reload.

Download Barrier to your Raspberry Pi computer

Now turn to your Raspberry Pi, open a terminal window (Ctrl-Alt-T if you didn’t know), and run:

sudo apt install barrier

Once installation is complete, Barrier should appear in the Accessories drop-down menu, which you can access via the main menu icon (the Raspberry Pi logo in the top right-hand corner). Select Barrier and, this time, choose Client.

If you leave Auto config selected, Barrier should just work, as long as the screen name is correct (you can change this by clicking Barrier and then Change settings) and matches the name you told the server.

And there you have it. You can now use your mouse and keyboard across both your computers. And, if you have enough desktop space for even more monitors, you can continue to add devices to Barrier until your room ends up looking something like this:

A man standing in front of a wall made of computer screens

If you use Barrier to clean up your workspace, make sure to share a ‘before’ and ‘after’ photo with us on Twitter.

47 comments
Jump to the comment form

Avatar

How does this differ to Synergy? It looks like a direct copy. Is it encrypted by default? Synergy is not encrypted for the free version.
Also, does it work well with the server being either Windows or linux? Syngergy can be quite ropey.
Is it open source?

Reply to Mr Wheeliebin

Avatar

It is an open source fork of Synergy, the encryption is enabled by default here.
I’ve not tried it with the server on Linux
Yes it’s open source:
https://github.com/debauchee/barrier/

Reply to Gordon Hollingworth

Avatar

Hi Gordon,
That’s mean it is secure to use even thought I’am typing sensitive information like passwords? What about the security? In the MacOS there is a warning that said: “Barrier” cannot be opened because the developer cannot be verified. MacOS cannot verify that this app is free from malware.
If it is secure to use, will be a great app that I will be using for long, thanks!

Reply to Douglas

Avatar

All that warning in MacOS means is that the developer hasn’t submitted the application to Apple for code signing. It doesn’t necessarily mean there is anything at all wrong with it; it just means they didn’t want to jump through all of Apple’s (sometimes complicated and expensive…) hoops…

Reply to Simon Long

Avatar

Thanks Simon! I will be trying Barrier!

Reply to Douglas Navas

Avatar

I presume the Barrier people added the encryption bit then. Nice. Free as in free beer.

Reply to Mr Wheeliebin

Avatar

> Free as in free beer.
According to the LICENSE file on Github it’s GPL v2. So it’s actually free as in speech and not as in free beer. ;)

Reply to Misel

Avatar

This work looks great, but it is ok if you can see both computers on the same network. I have a USB connector (OEM) to do this at the mo, as one PC runs a VPN, and most VPNs block local network access (eg 192.*) to prevent network bridging.

Reply to Ian

Avatar

What am I missing here? I have multiple screens and usually dedicate one to a VNC session on my RPi when I’m coding.

Reply to Jerry Wasinger

Avatar

I’ve been using Barrier for a few weeks and find it works perfectly. One thing to be aware of is the Print Screen key disables barrier and locks the keyboard and mouse to the currently active screen, pressing again resumes normal operation.

Reply to Ste

Avatar

Gordon, I have run Synergy server on a Pi and on a PC Linux box with Mint and it works very well. The only problem I have ever had with Synergy is getting Windoze clients to connect automatically. This is presumably due to having a password protected login set up on the Windoze clients.

Reply to Mark

Avatar

@Jerry – the way I’ve been using Synergy (of which Barrier is a fork) for years is to use one keyboard/mouse for multiple computers. So if you had a monitor on your raspberry pi, you wouldn’t need to keep two keyboards on the desk. For instance, I have my Windows work laptop, my Macbook, and my linux desktop. I can move seamlessly between them throughout the day using the same keyboard and mouse, sharing clipboard contents.

Reply to John H

Avatar

Jerry, it sounds like you have multiple monitors on a single PC and connect to another computer over VNC with it’s video output being displayed on your [second] monitor. Synergy (or Barrier) allows your mouse pointer to move off the edge of your screen and onto the screen of another computer on the same network, taking the keyboard and clipboard with it and allowing you direct control of that second (or third, or fourth, etc) computer, whether it is a PC, Windoze box, Mac or Pi.

Reply to Mark

Avatar

A word of warning for polyglots: Barrier is fundamentally flawed in that it send over characters (letters you typed) instead of scan codes (which physical key you pressed).
This makes barrier virtually unusable with multiple keyboard layouts.
For example I want to type a 4 on one of the clients with English QWERTY layout. But on the host I have Czech QWERTZ selected. So I press the 4 key, which tries to type č, but since there is not č on an English keyboard it types a c. So I press 4 and get c.
It usually works if you make sure both host and client have the same layout selected, but that’s very tedious and even then it still breaks sometimes for non-english layouts.
It’s a nice concept, but it only works if you’re using English and nothing else.

Reply to Dave

Avatar

Just tried with Windows 10 as host.
Appeared to be working well until I tried to type vertical bar on RPi terminal session … and it appeared as greater-than sign.
So – issue with keyboard language.
My Win 10 is configured as UK keyboard – as is my RPi and a directly attached USB keyboard on RPi correctly shows UK keys as typed.
Starting new new terminal session on RPi did not resolve it.

Reply to Paul Webster

Avatar
Avatar

There’s nothing stopping you from connecting a monitor to a Raspi when it’s broadcasting VNC. The way VNC works is by mirroring the display. So, you can always see what’s happening on the other computer. Of course, you then duplicate the screen if you want to work on it. But I prefer that way since I don’t want to crank my neck sideways for too long, anyway.
Still, more options is better since everyone works differently. Thank you for posting.

Reply to Harry Hardjono

Avatar

Interesting…. Unfortunately, I don’t have room for a second (let alone third, fourth, fifth…) monitor on my desk. So it’s KVM switches for me. I got my first one over 20 years ago and have never looked back.

Reply to W. H. Heydt

Avatar

What GTK theme is the Pi using? It’s nice!

Reply to Justin

Avatar

I developed this similar system in 2016 that works with computers using X: https://github.com/mobluse/x2x
It uses x2x.

Reply to Mikael Bonnier

Avatar

Jerry,
The main thing you’re missing is latency free, realtime graphics.

Reply to Adrian

Avatar

Does this work with dual monitors?

Reply to Ted

Avatar

I have 6 pi screens that I switch back and forth and would like get this running. I did the apt install and it is in my accessories folder. I call it up and get the main box. click on Client (I have already got it installed on my mac). I click on apply then nothing happens! Also tried to get the tarball and build it, but it says that I dont have access rights to the remote repository.

Reply to Bob

Avatar

My Pis generally run web apps on Raspbian Lite, so command line interface only, SSH is all I need.
But this looks interesting for some of our office Pis that have big screen displaying infrastructure status.

Reply to Anders

Avatar

@Adrian and @Mark, I just realized I did not read the explanation of Barrier very well – now I get it. This code allows the use of a single KBD/Mouse across multiple computers. However, they each connect to a dedicated monitor. Think I’ll stick with my VNC solution since it allows me to drag my RPi desktop over to my main screen when I want it front and center.

Reply to Jerry Wasinger

Avatar

I’ve been using Synergy for a few months and love it. I have a windows 10 tablet as the client, I just use for Spotify, notes, a task listet and have it positioned under my monitor.

Reply to Ricky

Avatar

Does it work between a laptop screen and a monitor?

Reply to Dan

Avatar

I remember doing something similar more than a dozen years ago.

vnc server on the keyboard/mouesless machine combined with a vnc client on the main machine that didn’t display the remote machine but detected the pointer moving off the local screen then sent keyboard/mouse input to the vnc server.

Worked fine unless the vnc server crashed when the client had grabbed the pointer and keyboard. Hopefully Barrier (and synergy) have fixed that type of issue.

Reply to thagrol

Avatar

What are it’s technical requirements?
By example, does the Server’s processor or RAM impact it’s capabilities?
If I were to use a Raspberry Pi 4 as a server, because it supports two monitors, would there be any advantage in using a Pi with more RAM?

Reply to steven

Avatar

This is very appreciated and so easy to set up! Thanks!

Reply to Mario

Avatar

How would you set barrier to starting automatically after login in raspbian?
I have googled and only found how to run python programs after booting. There must be a simpler way to set this as in other OS.

Reply to Mario

Avatar

You could put the command to start barrier into /etc/rc.local, with an ampersand (&) at the end.

Cheers,
Norm.

Reply to Norman Dunbar

Avatar

Doing a sudo apt install barrier gives me the Unable to locate package barrier error on raspberry pi

Reply to Ron

Avatar

@Mario,
It took me a while to figure out how to get Barrier to autostart.
Firstly make sure that your barrier connection is working and then exit Barrier (Barrier > Quit), this saves the current settings.
In the file /home/pi/.profile add this to the end of the file
barrier &
Save and restart.
Ste

Reply to Ste

Avatar

Trying to do the same but can’t find that file. Only have a.txt and rpdiags.txt in that folder.
I am new to this.

Reply to Jonathan White

Avatar

To access file.
open terminal and use sudo mousepad /home/pi/.profile

Reply to Jonathan White

Avatar

@Ron,
You’ll most likely have to upgrade your Raspbian to Buster.

Reply to Thorsten

Avatar

I managed to get this working on my Pi 4 using my WIndows 10 laptop as the server. I had to use the workaround in https://github.com/debauchee/barrier/issues/134 to get the keyboard layout on the Pi correct – without that it gave me a US keyboard layout – both Pi and laptop set to UK keyboard layout already (including system locale on Windows 10).

Reply to andrum99

Avatar

I really appreciate video tutorials like these. :) Very helpful.

Reply to Esbeeb

Avatar

could not have expected this to be possible, never thought of this. lol

Reply to SingingCoyote13

Avatar

Nice Thing. Works great for me. But i would like to see a version for Android too. I’m using Samsung Dex for some applications for work (MS Office, Outlook etc.) cause i don’t use Windows anymore. Then i could work with only one keyboard and mouse.

Reply to archie

Avatar

Great program use between my PC and pi4. Please note if you not running windows standard 100% fonts can casue problems with mouse pointer . Also as a gamer I had to turn on “switch on double tap” which means have to hit side of screen 2x fast to switch over.

Reply to David Norman

Avatar

This looks great. I am fairly new to pi’s and raspian etc. I have tried installing using : ‘sudo apt install barrier’ after ‘sudo apt-get update’ and it shows ‘Reading package lists… Done ; Building dependency tree; Reading state information… Done; E: Unable to locate package barrier.
Im confused as I believe i followed the instructions in the video

Reply to paul williams

Avatar

Thank you so much. I didnt think this would be possible but now I’ve connected my mouse and keyboard with Laptop and Rpi4. Thanks again!

Reply to Teslicek

Avatar

Thank you so much i was looking this article but now follow your instruction i have done thanks again

Reply to Muhammad Shakeel

Avatar

Looks very interesting. Might give it a go. Thanks

Reply to John

Avatar

Thank you, Gordon. It is a great tool and useful video

Reply to Marlon Fraile

Leave a Comment