TimeMachine Backup to a Linux Server

published:

I tested these instructions on Ubuntu Server 22.04, but they should work anywhere you can install Samba.

Install Samba:

sudo apt install samba

Add a specific user for the TimeMachine backup. This user doesn't need a home directory, a Unix password or a login. After creating the user, add a password for Samba.

sudo adduser --no-create-home --disabled-password --disabled-login timemachine
sudo smbpasswd -a timemachine

Edit the Samba config /etc/samba/smb.conf and add the following:

# add these lines for TimeMachine support:
fruit:aapl = yes
fruit:nfs_aces = no
fruit:model = MacSamba
server min protocol = SMB2_02
server max protocol = SMB3
 
# we set multicast to 'no' and install Avahi instead
multicast dns register = no
 
# add a share for TimeMachine:
[TimeMachine]
path = /srv/timemachine
comment = TimeMachine Backup
vfs objects = catia fruit streams_xattr
fruit:time machine = yes
fruit:time machine max size = 2000G
valid users = timemachine
writeable = yes
browseable = yes
guest ok = no

The path must point to an empty directory. The fruit:time machine max size should be at least double the size of your Mac disk.

Start Samba:

sudo systemctl start smbd.service
sudo systemctl enable smbd.service
# or, if you made changes, restart:
sudo systemctl restart smbd.service

You may need to open the following ports in the firewall on your server for Samba to work correctly:

You can also install Avahi, so that your Mac automatically finds the backup volume:

sudo apt install avahi-daemon

Add the service file /etc/avahi/services/samba.service

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_smb._tcp</type>
    <port>445</port>
  </service>
  <service>
    <type>_device-info._tcp</type>
    <port>0</port>
    <txt-record>model=MacSamba</txt-record>
  </service>
  <service>
    <type>_adisk._tcp</type>
    <port>9</port>
    <txt-record>dk0=adVN=TimeMachine,adVF=0x82</txt-record>
    <txt-record>sys=waMa=0,adVF=0x100</txt-record>
  </service>
</service-group>

Restart Avahi:

sudo systemctl restart avahi-daemon

You may need to additionally open a port for Avahi:

Now you can add this network share as a new backup volume in your TimeMachine settings. It should appear automatically in the available disks if you are in the same network as your server.


Have a comment? Drop me an email!
This helped you? Consider buying me a ♥ coffee ♥

Latest Notes

  1. Shadowdark - Player-Driven Death Mechanics
  2. Using Syncthing to back up photos from an Android phone
  3. Real Time Beat Prediction with Aubio
  4. Performant Images on the Web
  5. Automatically backup your complete Linux system when connecting to a specific wifi network