Skip to content

Instantly share code, notes, and snippets.

@karlkfi
Created September 10, 2015 15:30
Show Gist options
  • Save karlkfi/587155a2c8b2cd7d15ce to your computer and use it in GitHub Desktop.
Save karlkfi/587155a2c8b2cd7d15ce to your computer and use it in GitHub Desktop.
Temporarily authorize a Mac with an SSH key from a USB drive
#!/usr/bin/env bash
hours=$1
script_dir="$(cd "$(dirname "${BASH_SOURCE}")" && pwd)"
drive_mount="$(cd "${script_dir}/.." && pwd)"
key_path="${script_dir}/id_rsa"
if [ -z ${hours} ]; then
hours=1
fi
/usr/bin/ssh-add -D
/usr/bin/ssh-add -t ${hours}H "${key_path}"
/usr/sbin/diskutil umount force "${drive_mount}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment