DEV Community

Cover image for Keybase File Sync On Demand
YourTech John
YourTech John

Posted on

Keybase File Sync On Demand

Keybase file sharing

I do 90% of my development inside a Linux VM and use VSCode + Remote SSH. In addition, I maintain a sprawling notebook on this development vm. On occasion, I'd like a copy of some of these notes on another device. Up until today, I usually have to copy/paste the contents or use scp to extradite the file. Obviously there are better solutions.

I don't necessarily want these to be synchronized to all my other devices automatically, and I don't need the ability to edit these notes on my phone. What I want is the ability to browse the files from another device and access it on demand. I've been a long-time keybase user (ytjohn), and decided to make use of their file sharing. Unlike Dropbox, Google Drive, and Box, there is no sync model. The files stream in on demand. I decided to create a a one-way rsync of my notebook to the keybase filesystem. I also decided to use a separate keybase account for my VM.

I installed the keybase client on my development vm and gave it its own separate account. I could have used my main account, but I feel more comfortable keeping the account on this VM separate from my main account. All it's going to be used for is files. I registered my second keybase account as "ytjohndev".

I did the basic install and you can sign up with only providing an email address. No need for a password just yet. For safety, you should do a keybase paperkey and back that up somewhere.

ytjohn@dev:~$ keybase signup
Your email address: hidden@example.cpm
Your desired username: ytjohndev
A public name for this device [home computer]: dev
▶ INFO Signed up and provisioned a device. [tags:ENG=...]

Welcome to keybase.io!

   - you are now logged in as ytjohndev
   - your profile on keybase is https://keybase.io/ytjohndev
   - type 'keybase help' for more instructions

Found a bug? Please report it with `keybase log send`

Enjoy!

The next step is to share files with myself. On Linux, keybase creates a series of mounts at "/keybase".

On Linux, you want to browse to "/keybase/private". One will exist of "/keybase/private/yourusername", and you can immediately
start copying files there. There are also implicit directories that don't appear, but the kbfs will report as already existing. To
share with another user, you would put a file into a directory of "/keybase/private/yourusername,friendsusername".

ytjohn@dev:/keybase/private$ mkdir ytjohndev,ytjohn
mkdir: cannot create directory ytjohndev,ytjohn: File exists
ytjohn@dev:/keybase/private$ cd ytjohndev,ytjohn
ytjohn@dev:/keybase/private/ytjohndev,ytjohn$ ls
ytjohn@dev:/keybase/private/ytjohndev,ytjohn$ echo hi > hi.txt

On my regular keybase, I received no notification of this. On my Mac, keybase was in "/Volumes/Keybase". The private directory was
not showing my shared files. However, once I cd'd into "ytjohn,ytjohndev", then keybase gave me a notification about shared files, and I was
able to see the shared file.

jh1:~ ytjohn$ cd /Volumes/Keybase
jh1:Keybase ytjohn$ ls private
ytjohn  ytjohn,friend1  ytjohn,friend2  ytjohn,doesnothaveathirdfriendintheworld
jh1:Keybase ytjohn$ cd private/ytjohn,ytjohndev  # keybase popped up a sharing notification at this point
jh1:ytjohn,ytjohndev ytjohn$ ls
hi.txt

Now I just needed to sync my files back on my dev vm.

ytjohn@dev:~$ rsync -aqr $HOME/Documents/notebook /keybase/private/ytjohndev,ytjohn/

Then back on my MBP, I can see them.

jh1:ytjohn,ytjohndev ytjohn$ ls /Volumes/Keybase/private/ytjohn,ytjohndev/notebook/
2020  inbox

Finally, I put this in crontab on my dev VM for every 10 minutes. Run crontab -e to edit my personal crontab.

*/10 * * * * rsync -ah /home/ytjohn/Documents/notebook/ /keybase/private/ytjohndev,ytjohn/notebook --delete

Note: the --delete will delete files in "notebook/" not existing in my source of $HOME/Documents/notebook. As such,
if I want to send back a file from another system, I should not put it in the notebook directory.
Now I'll lets make a few test cases.

ytjohn@dev:~/Documents/notebook$ echo "this is a cronjob test" > crontest.txt
ytjohn@dev:~/Documents/notebook$ echo "this is a delete test" > /keybase/private/ytjohndev,ytjohn/notebook/deletetest.txt

Let's sit here for many minutes waiting for crontab to run. Make sure to do nothing else except watch the clock tick every 2 seconds.

ytjohn@dev:~/Documents/notebook$ watch ls -l /keybase/private/ytjohndev,ytjohn/notebook

Watching...

Every 2.0s: ls -l /keybase/private/ytjohndev,ytjohn/notebook/     dev: Thu Jul  9 13:38:27 2020

total 2
drwx------ 1 ytjohn root 990 Jul  7 14:49 2020
-rw------- 1 ytjohn root   0 Jul  9 13:36 deletetest.txt
drwx------ 1 ytjohn root 566 Jul  9 13:02 inbox

And success:

Every 2.0s: ls -l /keybase/private/ytjohndev,ytjohn/notebook/     dev: Thu Jul  9 13:41:14 2020

total 3
drwx------ 1 ytjohn root 990 Jul  7 14:49 2020
-rw------- 1 ytjohn root  23 Jul  9 13:36 crontest.txt
drwx------ 1 ytjohn root 566 Jul  9 13:02 inbox

Final Thoughts

If the goal is a two-way sync, syncthing would be a better fit. If you want to share with a larger group, Keybase Teams makes that possible. In fact, what we did was create a two-person private team. I had also considered just pointing my editor to edit directly in keybase directory, but this would create traffic to keybase on each save. Additionally, if keybase was having issues, it could render the directory unavailable.

Top comments (0)