password management - roubles/macmounter GitHub Wiki

It is not recommended that you store passwords for remote servers in your config files. For ssh mounts, you can use passwordless logins. For protocols that do not support passwordless logins, you can use OSX's keychain. macmounter contains some simple shell scripts (getpwd.sh and setpwd.sh) to aid using OSX's keychain.

These shell scripts are in the source code in the sh/ folder.

Instead of doing:

MOUNT_CMD=/sbin/mount -t smbfs //roubles:[email protected]/remotefolder /Volumes/example

where 'whatmeworry' is your password in clear text

You should rather encapsulate the mount command in a shell script:

MOUNT_CMD=/Users/roubles/Scripts/mount_samba.sh

And, your shell script, can use getpwd.sh and setpwd.sh to use the keychain. You will need to run the script once, manually, to actually set the password in the keychain.

#!/usr/bin/env bash

# pound defines
USER="roubles"

# Get password from keychain.
# Here we look for a password for account 'samba_mount'
PWD=$(/path/to/macmounter/sh/getpwd.sh samba_mount)
if [ -z $PWD ](/roubles/macmounter/wiki/--z-$PWD-)
then
    # No password set. Interactively obtain password.
    # This script must be run manually once to set the password.
    # Here we set the password for account 'samba_mount'
    /path/to/macmounter/sh/setpwd.sh
fi

# Get password from keychain.
# Here we, again, look for a password for account 'samba_mount'
PWD=$(/path/to/macmounter/sh/getpwd.sh samba_mount)
HOST="example.com"
REMOTE_FOLDER="remotefolder"
LOCAL_FOLDER="/Volumes/example"

# Finish big
/sbin/mount -t smbfs "//$USER:$PWD@$HOST/$REMOTE_FOLDER" $LOCAL_FOLDER