Derek Sivers

How to sync Mac and Linux /home

2024-08-31

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:

  1. SSH into the remote server, so you can type the password to mount the encrypted partition.
  2. rsync -av --delete between them
  3. 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.