Storing password for Middleman-Deploy (and simular) in the Mac keychain

On a mac, if you do not want to keep passwords (or other data) in plain text in the config.rb, you can store it in the keychain.

Retrieve like this:

deploy.password = `security 2>&1 >/dev/null find-generic-password -ga account_name_for_password |ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/'`

(Replace account_name_for_password with the account name for your password. )

A dialog will ask if you allow the access.

Instructions on how to add a password to the keychain: http://blog.macromates.com/2006/keychain-access-from-shell/

(P.S: Sorry about the ”Releases” category, but the forum system will not let me post without choosing a category, and no suitable category was available.)

For the sake of cross-platform compatibility I’d put that code into a shell script and store the passwords in environment variables.

You can also store “ENV” values in the Bundler config file. This is what I use for the middleman site itself, which needs private keys to deploy but is hosted publicly.

http://gembundler.com/v1.3/bundle_config.html

Accessed via: Bundler.settings["key_name"]

The big advantage in using the Keychain CLI is that you don’t have to store clear text passwords on disk.