Skip to content

Instantly share code, notes, and snippets.

Last active September 22, 2022 23:33
  • Star 31 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Script to automatically look for Apple TimeCapsule devices and mount/umount them under GNU/Linux. See for info and explanations.
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# for more details.
# Version 3, enhanced for Ubuntu 13.X+, Fedora 19+, and similar distros.
# Runs on all GNU/Linux distros (install cifs-utils)
# Author: Daniel Graziotin <dgraziotin AT task3 DOT cc> -
# Purpose: Check if there is a TimeCapsule in your network and mount it
# for use it under Gnu/Linux. Unmount it if it is already mounted.
# The mount point is created and destroyed after use (for prevent
# automatic backup software to backup in the directory if the device
# is not mounted)
# Instructions:
# 1) Install cifs-utils (sudo apt-get install cifs-utils)
# 1) Change the first four variables according to your configuration.
# 2) Run this program at boot when your network is already
# set up. Also, run it on logoff to umount Time Capsule.
TIMECAPSULE_IP="" # e.g. ""
TIMECAPSULE_VOLUME="/Time\ Capsule" # also try "/Data"
TIMECAPSULE_PASSWORD="YOURPASSWORDHERE" # prefix special characters, e.g. \!
MOUNT_POINT=/mnt/timecapsule # no need to create the directory
IS_MOUNTED=`mount 2> /dev/null | grep "$MOUNT_POINT" | cut -d' ' -f3`
if [[ "$IS_MOUNTED" ]] ;then
CHECK_TIMECAPSULE=`smbclient --no-pass -L $TIMECAPSULE_IP 2>&1 > /dev/null | grep -m1 -i apple`
if [[ "$CHECK_TIMECAPSULE" =~ "Apple" ]] ;then
echo "mount.cifs $TIMECAPSULE_PATH $MOUNT_POINT -o pass=$TIMECAPSULE_PASSWORD,file_mode=0777,dir_mode=0777,sec=ntlm" | /bin/bash
Copy link

There was an issue with ubuntu 17.10 unable to mount due to version mismatch of samba protocol version.
Adding vers=1.0 solves it.

echo "mount.cifs $TIMECAPSULE_PATH $MOUNT_POINT -o pass=$TIMECAPSULE_PASSWORD,file_mode=0777,dir_mode=0777,sec=ntlm,vers=1.0" 

Copy link

Arc676 commented Sep 29, 2018

This doesn't work on Ubuntu 18.04. Yields:

Unable to find suitable address.

dmesg | tail yields

CIFS VFS: Error connecting to socket. Aborting operation.
CIFS VFS: cifs_mount failed w/return code = -111

Copy link

l3x commented Oct 12, 2018

This worked for me on Linux 4.14.74-1-MANJARO:

mkdir -p /mnt/timecapsule 
mount.cifs //$TIMECAPSULE_IP/Data /mnt/timecapsule -o user=$USER,pass=$PASSWORD,file_mode=0777,dir_mode=0777,sec=ntlm,vers=1.0

Copy link

panoriega commented Jul 31, 2020

I made a simple change on the script, I removed the smbclient check, because the security is different in TimeCapsule now, and also added parameters to mount command, with sudo. I also created a daemon script to run it on startup.

UID=1000 #User ID

if [[ "$IS_MOUNTED" ]] ;then
    echo "unmounting TimeCapsule"
    sudo umount $MOUNT_POINT
    sudo rmdir $MOUNT_POINT
    echo "unmounted"
    echo "mounting TimeCapsule"
    sudo mkdir $MOUNT_POINT
    echo "sudo mount.cifs $TIMECAPSULE_PATH $MOUNT_POINT -o password=$TIMECAPSULE_PASSWORD,file_mode=0777,dir_mode=0777,sec=ntlm,uid=$UID,vers=1.0" | /bin/bash
    echo "mounted"

Copy link

ipatch commented Jul 31, 2020


any reason you chose to use mount.cifs over mount -t smbfs ?

I remember´ reading somewhere that calling one of these commands directly from a CLI is suppose to be a no no 👎

i run macOS nevermind

Copy link

brolal commented Dec 11, 2021

Copy link

@brolal I hope that someone can help you here. My TimeCapsule has long been dead.

Copy link

not working on ubuntu 22.04 or parrot linux, I simple need to emulate windows just for my time capsule. Please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment