Skip to content

Instantly share code, notes, and snippets.

@krejac
Created March 22, 2017 12:47
Show Gist options
  • Save krejac/6db8f8a9a9a48482a85c1b08ffdccbed to your computer and use it in GitHub Desktop.
Save krejac/6db8f8a9a9a48482a85c1b08ffdccbed to your computer and use it in GitHub Desktop.
ssh to an iCloud connected mac using Back To My Mac
#!/bin/bash
ACCOUNT=$(echo "show Setup:/Network/BackToMyMac" | scutil | sed -n 's/.* : *\(.*\).$/\1/p')
if [ ! -n "$1" ]; then
echo "ssh to which Mac? "
read MAC
# Uncomment the following two lines if you need to login to the remote host with a different user than the current local user.
#echo "As who? "
#read USER
if [[ USER ]]; then
ssh $USER"@"$MAC"."$ACCOUNT
else
ssh $MAC"."$ACCOUNT
fi
else
ssh $1"."$ACCOUNT
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment