Electron. Rsync. Raspberry Pi.

Thomas
The Startup
Published in
5 min readJan 25, 2021
via Canva

In my last article, I walked you through how to setup SSH with a Raspberry Pi so that we could log in without needing to enter a password. In this article, we are going to talk about how to connect everything so that we can use our Electron Rsync client to connect to the Raspberry Pi and sync our files from our computer to the Raspberry Pi. If you want to catch up or reference the previous article feel free to check it out below.

Since I did some due diligence at the beginning by making the code modular and reusable there wasn’t a ton of extra work to add the ability to do remote syncs with Rsync from a coding standpoint. The majority of the work was centered around getting SSH to authenticate correctly with the Electron GUI process. I have decided to make the Eikona Sync proof of concept publicly available if you would like to clone and run the code locally or submit any PRs and issues.

Pre-setup

Below are the steps that we originally did in the Password-less Raspberry Pi article towards the end of that tutorial. These steps must be re-executed for the local context of our Eikona Sync project. I chose to redo these steps within the VSCode terminal that the Eikona Sync project is currently opened in.

Start your SSH agent

The first thing you do is start your ssh-agent with

eval "$(ssh-agent -s)"

This will start your SSH agent within the context of your current terminal. This is important because once the SSH private key is added to this current instance of the SSH agent it will be stored within this terminal context until you close the terminal or VSCode. This will allow our Electron App to authenticate with our remote host without requiring us to accept input from the user for their password to the remote host when Rsync is syncing files.

Next, you add the generated private key to the remote host with a command similar to

ssh-add -K ~/.ssh/aragorn_euler-z

Finally, we will test the password-less SSH connection with our remote host to ensure that we have everything set up correctly below.

Add your SSH private Key to the Agent

Once we can properly login to our remote host we exit that SSH session and start our Electron app with

npm run electron:serve
Test Logging into the remote host

Now we can continue with the Electron Rsync GUI and sync our files from our computer to the Raspberry Pi. If you run into any issues make sure that you typed the commands correctly or that your SSH keys were generated and set up correctly. You can always reference the previous guide I wrote about generating and adding SSH keys to a remote host.

Remote Rsync GUI

As you can see in the screenshot above I added another button to indicate whether you are doing a local or remote sync and made some modest adjustments to the UI depending on which type of sync you are interested in doing.

Remote Client Address

The biggest difference is that for the remote sync functionality to work you have to ensure that your password-less SSH is set up and working correctly with the host you want to sync with. You will also notice in the UI that you have to enter in the user and host IP address with the corresponding path to the directory you are wanting to sync between. I recommend you sync to the home directory of the user that you created the SSH key for to avoid any permissions issues, otherwise, the Rsync command can potentially fail. Note: Since this is a POC ensure that you type the remote connection string correctly as there is currently no regex validation to check that you did not mistype the connection string.

Rsync sync

Otherwise, the functionality and underlying code are identical for both the local and remote sync. When you log in to your Raspberry Pi or remote host you should then see the corresponding synced directory similar to what is in the screenshot below.

Rsync sync results on the Raspberry Pi

When you put everything together we get

Demo of the Sync

In the above demo, you can see how the Electron Rsync GUI is supposed to work. Note: I did ls on the Raspberry Pi while the sync was in-progress to show that the files were being copied and again once the sync was completed.

I hope you found this article interesting and helpful; in the future, I might add OAuth login flow to the Eikona Sync POC and other features. Stay tuned!

I need your help to continue writing on topics that interest you and help you grow on your journey to become a 10x Engineer! Please fill out the form below to help guide future topics.

--

--