How to sync Mac and Linux /home
the problem:
My main computer is a Linux/BSD desktop, but I also use a Mac laptop for recording and travel. This created a problem keeping them in sync.
I don’t like that the MacOS user’s home has directories like Movies and Pictures that we can’t delete, or that ~/Library is filled with Mac-only crap I don’t want on my other computer. Also, why did Apple make it /Users/me and not /home/me?
the solution: synthetic.conf
We can use the fact that Mac has no /home/ to our advantage. In your terminal, type man synthetic.conf to read about it.
Assuming username “me” here, (meaning: replace “me”, below, with your actual username) I type, in the terminal:
sudo vi /etc/synthetic.conf
Then I add this one line, which has to be separated with a [tab]:
home Users/me
Save, verify, then reboot.
/home/me = /Users/me/me
Make a new directory ~/me which will now be /home/me
mkdir ~/me
touch /home/me/hello
ls ~/me
ls /home/me/
Verify it’s working, that whatever you put into /Users/me/me/ is also now in /home/me/ and vice-versa. Then…
rsync
Of course you have to be able to SSH into your other computer, so if not, go figure that out first. I’ll assume that “desktop” reaches your Linux/BSD/other computer, probably via a nice entry in ~/.ssh/config
Then use free and lovely rsync to synchronize:
rsync -av --delete desktop:/home/me /home/
When it’s done, verify that everything from /home/me on your Linux/BSD computer is in /home/me on your Mac. Then move a file from your Mac Desktop or Documents into /home/me/ and copy it back:
rsync -av --delete /home/me desktop:/home/
When it’s done, verify that whatever you just added from your Mac is now on your Linux/BSD computer. I like to go back and forth a couple times to be absolutely sure it’s working correctly, to make sure I can rely on it.
I use these two commands so much that I made them one-line shell scripts in /home/me/bin/ so I can just type “gethome” when I first open the Mac, or “puthome” when I’m done on the Mac.
Note this also works very well for a remote copy of your home directory on an encrypted remote server as described in my “Tech Independence” page. In that case, the shell script has three steps:
- SSH into the remote server, so you can type the password to mount the encrypted partition.
- rsync -av --delete between them
- SSH into the remote server to unmount the encrypted partition.
Whatever’s not in /home/me is Mac-only
This /home/me where you’ll keep everything of value — everything you share between computers. Whatever’s in your /Users/me directory but not in your /Users/me/me is Mac-only, and won’t be copied to your other computer. So whatever you have in the MacOS defaults of Desktop, Documents, Downloads, Library, Movies, Music, Pictures, and Public is only on the Mac. If you want to sync anything in there to your other computer, move it to /home/me/
I actually like this if I’m travelling with the Mac laptop and want to download some music or movies into ~/Music or ~/Movies but wouldn’t want to sync that 20GB of media to my other computer.
But most of all, I love having /home/me be the same on all computers, so I can be writing or coding on the Mac laptop on a train, then get home and type “puthome”, and get back to work on my desktop.
Another nice side-effect of keeping them in sync is if I accidently delete a file on one computer, I can pick up the other one to restore it. Or if the entire computer is stolen or destroyed, I can just curse a bit, then get back to work on the other.
Have you tried Syncthing? It’s perfect for this scenario.
I've heard good things about it, but I prefer this manual method. And the main point of this article was to let people know about synthetic.conf on Mac so you can have /home/$username on both computers. — Derek
Looks like you use Mac and non-apple phone. Do you think update to sive.rs/uses this page?
Done. Thanks for the nudge. — Derek
Love this! And so timely….Recently installed Ubuntu on an old Mac and want to be able to sync from my work Mac to my own machine for some personal docs.
Do you have everything on your Linux in your home/me directory, so everything is available on your Mac, or just some select stuff you want to have access to on both?
I keep everything in /home/derek yeah. Even important config files that are copied to /etc/ - I keep the master copy in a subdirectory of /home/derek/ - The big idea is that when I'm travelling with only the Mac laptop I need to have access to everything in case my server dies or I just feel like coding nginx.conf or whatever. So my home directory has everything I need, no matter what computer I'm on. — Derek
Nice writeup, Derek.
In your response to Clive you mentioned keeping your config files in your home dir, I do that too.
However, instead of copying it every time I just link them with ln(1), e.g:
ln -s /home/derek/config/tmux ~/.tmux.conf
Extra points - I track changes in this /config dir with a (local only) git repository.
I’ve got this up and running on my MacBook so I can connect to my Linux laptop and sync with it using “gethome” or “puthome” scripts.
Am I correct that if I’m working on the Mac and then enter “gethome” instead of “puthome” it’ll download the /home/me directory from my Linux laptop and lose anything new I’ve been doing on the Mac?
Is there a safety to avoid this? Other than, “don’t be daft!” :)
Yep! Keep a backup in a 3rd place. Once or twice a year I make that mistake, and have to go pull back my changes from a USB stick or remote server or something. — Derek
unison is really good for sync. I use it keep sync a local dir for remote dir.
Does this work smoothly for programs that read configuration files on /Users/me? Do you have to run them with options to tell them to look for configuration files in /home/me?
For the few that I want to be the same on both computers (like SSH) I symlink /home/me/{dir} into /Users/me/{dir} — Derek
I do this but with a folder named ~/Sync on all machines. I used to use manual rsync but started using SyncThing.
Initially, SyncThing had really annoying problems with connectivity and syncing and using ST proxy addresses. Then, I configured all my ST nodes using the 100.x.x.x TailScale IP addresses. It’s been bulletproof ever since.
unison is stable one-way sync alternative to rsync.