Backing up part 2 : Using Linux as a Time Machine backup destination

While Time Machine is an excellent backup solution for macOS, external drives aren’t always the most convenient option, especially if (like me) you already have a Linux server with plenty of storage. By configuring Samba on your Linux server, you can use it as a network Time Machine destination, allowing automatic wireless backups without needing to plug in an external drive. Here’s how I set mine up (I used Ubuntu, but have put in commands for other distros as well).

On Linux

1. Install Samba on the Linux Server

# Ubuntu/Debian
sudo apt update
sudo apt install samba avahi-daemon

# RHEL/CentOS/Fedora
sudo dnf install samba avahi

2. Create a Directory for Time Machine Backups

sudo mkdir -p /mnt/timemachine
sudo chown your_username:your_username /mnt/timemachine
sudo chmod 755 /mnt/timemachine

3. Configure Samba

Edit the Samba configuration file:

sudo nano /etc/samba/smb.conf

Add this configuration at the end:

[TimeMachine]
   comment = Time Machine Backup
   path = /mnt/timemachine
   browseable = yes
   writable = yes
   valid users = your_username
   create mask = 0600
   directory mask = 0700
   spotlight = yes
   vfs objects = catia fruit streams_xattr
   fruit:aapl = yes
   fruit:time machine = yes

4. Set Up Samba User Password

sudo smbpasswd -a your_username

5. Restart Samba and Avahi

# Ubuntu/Debian
sudo systemctl restart smbd nmbd avahi-daemon
sudo systemctl enable smbd nmbd avahi-daemon

# RHEL/CentOS/Fedora
sudo systemctl restart smb nmb avahi-daemon
sudo systemctl enable smb nmb avahi-daemon

6. Configure Firewall (if needed)

# Ubuntu/Debian with ufw
sudo ufw allow samba

# RHEL/CentOS/Fedora with firewalld
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload

On the Mac

1. Connect to the Share

Open Finder and press Cmd + K, then enter:

smb://server_ip_or_hostname/TimeMachine

Enter your username and password when prompted.

2. Enable Time Machine to Use Network Drives

If the share doesn’t appear in Time Machine preferences, you may need to enable unsupported volumes:

sudo tmutil setdestination /Volumes/TimeMachine

Or directly set it:

sudo tmutil setdestination smb://username@server_ip/TimeMachine

3. Configure Time Machine

  1. Open System Settings → General → Time Machine
  2. Click the + button to add a backup disk
  3. Select your network share
  4. Start the backup

Tips and Considerations

  • Space Requirements: Ensure you have enough space on the Linux server (Time Machine typically uses 1-2x your Mac’s storage)
  • Performance: Network backups are slower than local ones, especially for the initial backup
  • Reliability: Use a wired connection for the first backup if possible
  • Size Limits: You can set a quota using Samba or filesystem quotas to prevent Time Machine from using all available space

Optional: Set a Size Limit for Time Machine

On your Mac, create a sparse bundle with a maximum size:

sudo tmutil setdestination /Volumes/TimeMachine
hdiutil create -size 500g -type SPARSEBUNDLE -fs "HFS+J" \
  -volname "Time Machine Backups" \
  ~/Desktop/TimeMachine.sparsebundle

Then move this to your network share and use it as the backup destination.

Backing up part 1 : Using SSH and rsync

I’m currently using a Mac as my main computer, but also have a Linux machine that I use for heavy lifting, but also for backups. Setting up SSH key-based authentication allows rsync to work seamlessly without password prompts, making backing up and file synchronisation much more convenient. This is particularly useful for automated scripts and frequent manual transfers. It’s what I use to ensure that I have a second copy of every file I download, and to keep my music collection in sync, and helps maintain that illusion that all my computers are actually one computer.

Configuration

1. Generate SSH Key on Mac (if you don’t have one)

First, check if you already have an SSH key:

ls -la ~/.ssh/id_*.pub

If you don’t have a key, generate one:

ssh-keygen -t ed25519 -C "your_email@example.com"

Press Enter to accept the default file location, and optionally set a passphrase (leave empty for truly passwordless, or use ssh-agent for security with convenience).

2. Copy Your Public Key to the Linux Server

Use ssh-copy-id to copy your public key to the server:

ssh-copy-id username@server_hostname_or_ip

You’ll need to enter your password one last time. This command copies your public key to ~/.ssh/authorized_keys on the server.

Alternative method (if ssh-copy-id isn’t available):

cat ~/.ssh/id_ed25519.pub | ssh username@server "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

3. Test the Connection

Try connecting via SSH without a password:

ssh username@server_hostname_or_ip

If it works without asking for a password, you’re all set.

4. Use rsync

Now you can use rsync without password prompts:

# Example: sync a local directory to remote server
rsync -avz /path/to/local/directory/ username@server:/path/to/remote/directory/

# Example: sync from remote server to local
rsync -avz username@server:/path/to/remote/directory/ /path/to/local/directory/

Common Options for rsync

  • -a : archive mode (preserves permissions, timestamps, etc.)
  • -v : verbose output
  • -z : compress data during transfer
  • -h : human-readable output
  • --delete : delete files in destination that don’t exist in source
  • --exclude='pattern' : exclude files matching pattern
  • -n or --dry-run : show what would be transferred without actually doing it

Troubleshooting

If you still get password prompts:

  1. Check permissions on the server:chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
  2. Verify SSH config allows key authentication (on server): Check sshd_config for:PubkeyAuthentication yes
  3. Check SELinux (if applicable on server):restorecon -R -v ~/.ssh