Created
April 28, 2020 10:04
-
-
Save beezly/dd307d5c4b2f88af73aa2aec246b0dba to your computer and use it in GitHub Desktop.
This pile of garbage will so SSM RDP on a Mac if you have the aws-cli and Microsoft RDP client installed. I'm not proud of this but it was useful to me.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh -e | |
LOCAL_PORT=$(( $RANDOM + 32767 )) # Handily $RANDOM gives a number between 0 and 32767, so this will give us a random port between 32767-65535 | |
REMOTE_PORT=3389 | |
target_id=$1 | |
aws ssm start-session --region eu-west-1 --target "${target_id}" --document-name AWS-StartPortForwardingSession --parameters "localPortNumber=${LOCAL_PORT},portNumber=${REMOTE_PORT}" & | |
SESSION_PID=$! | |
RD_TEMP=$(mktemp -d) | |
tidy() { | |
[[ -d $RD_TEMP ]] && rm -rf "${RD_TEMP}" | |
kill ${SESSION_PID} | |
} | |
trap tidy EXIT | |
> ${RD_TEMP}/ssm.rdp <<EOF | |
full address:s:127.0.0.1:${LOCAL_PORT} | |
prompt for credentials on client:i:1 | |
EOF | |
sleep 5 | |
open -F -W ${RD_TEMP}/ssm.rdp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment