Why should you build your own Time Machine Server?
Data is something we only truly value once it’s gone. For Mac users, Time Machine is the ultimate lifesaver. However, official Time Capsules are pricey, and using external USB-C drives can be cumbersome. If you have a spare Linux server or a Raspberry Pi running 24/7, turn it into a wireless backup station right now.
In fact, I once lost a whole week’s worth of code just because I was too lazy to plug in an external drive. Since setting up my own server, my Mac silently backs up whenever it connects to my home Wi-Fi. You’ll be completely hands-free and never have to worry about forgetting to plug in a cable again.
Which protocol to choose: SMB or Netatalk (AFP)?
To make macOS recognize a network drive, you generally have two main options:
1. Samba (SMB)
This is the modern protocol recommended by Apple. However, configuring Samba so that macOS correctly identifies it as a Time Machine drive can sometimes be finicky on older Linux distributions.
2. Netatalk (AFP)
Although Apple considers AFP a legacy protocol, Netatalk remains extremely stable for backup purposes. It supports macOS extended attributes very well, and connection drops are rare.
Quick comparison:
- Samba: Good speed, modern, but the accompanying mDNS/Avahi can be tricky to configure for the correct backup icon to appear.
- Netatalk: Plug-and-play, built for Mac, and highly reliable for long-term backups.
In this article, I choose Netatalk combined with Avahi because it’s stable and beginner-friendly.
System Preparation
I’m performing this on Ubuntu/Debian. If you’re using CentOS or Fedora, you just need to change the installation commands; the configuration files remain similar.
A vital word of caution: Never backup to the same drive as your operating system. Use a separate hard drive or partition. I once forgot to set a storage limit, and Time Machine ended up consuming 100% of the disk, causing the server to freeze and making it impossible to SSH in for repairs.
Step 1: Install necessary packages
Update the system and install netatalk and avahi-daemon so your Mac can discover the server on the local network.
sudo apt update
sudo apt install netatalk avahi-daemon -y
Step 2: Create storage directory and set permissions
Assuming your external drive is mounted at /mnt/backup_disk. We will create a specific directory and a dedicated user for backups.
sudo mkdir -p /mnt/backup_disk/timemachine
# Create a separate user for security, avoid using root
sudo adduser tmuser
# Grant ownership to user tmuser
sudo chown -R tmuser:tmuser /mnt/backup_disk/timemachine
sudo chmod -R 700 /mnt/backup_disk/timemachine
Step 3: Configure Netatalk
Open the /etc/netatalk/afp.conf file to set the server parameters.
sudo nano /etc/netatalk/afp.conf
Paste the following configuration at the end of the file, making sure to replace it with your actual path:
[Global]
hostname = My-Linux-Backup-Server
log file = /var/log/netatalk.log
log level = logger:info
zeroconf = yes
[Time Machine]
path = /mnt/backup_disk/timemachine
valid users = tmuser
time machine = yes
; Storage limit (e.g., 500GB = 512000 MB)
vol size limit = 512000
Why are these lines important?
time machine = yes: Forces macOS to recognize this as a dedicated backup drive.vol size limit: Very important. Time Machine is greedy; it will consume the entire disk if you don’t limit its capacity from the start.
Step 4: Configure Avahi (Service Discovery)
To have Finder automatically display the server name without manually typing the IP address, create a service file for Avahi.
sudo nano /etc/avahi/services/afpd.service
File content:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=TimeCapsule8,119</txt-record>
</service>
</service-group>
The model=TimeCapsule8,119 line helps the server display the iconic Time Capsule drive icon in Finder, giving it a professional look.
Step 5: Enable services
Run the following commands to apply the new configuration:
sudo systemctl restart netatalk avahi-daemon
sudo systemctl enable netatalk avahi-daemon
Connecting from macOS
On your Mac, follow these steps:
- Go to System Settings -> General -> Time Machine.
- Click Add Backup Disk.
- Select the server name you just set (e.g., My-Linux-Backup-Server).
- Log in using the
tmusercredentials created in Step 2.
The first backup is usually quite large (potentially several hundred GB). I recommend using a LAN cable for maximum speed; subsequent backups over Wi-Fi will be very convenient.
Real-world Operating Experience
After using this setup for a while, I’ve gathered a few key points to keep in mind:
- Hard drive format: On Linux, prioritize using
ext4. Avoid NTFS or exFAT because Netatalk’s permission management on these formats is poor and can easily lead to backup errors. - Check services: If the backup drive suddenly disappears, check the command
systemctl status avahi-daemon. In most cases, the issue is caused by this service hanging. - Speed: If you’re using a Raspberry Pi, prioritize using the USB 3.0 port for the hard drive to avoid bottlenecks during large backups.
Building your own Time Machine server not only saves you a significant amount of money on hardware but also gives you more control over your data. Good luck with your setup!

