Skip to content

Instantly share code, notes, and snippets.

@jonasfj
Created July 7, 2015 01:38
Show Gist options
  • Save jonasfj/3c8a140ba9d79ca46aa7 to your computer and use it in GitHub Desktop.
Save jonasfj/3c8a140ba9d79ca46aa7 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
# Test AWS credentials
if [ "$AWS_ACCESS_KEY_ID" == "" ] ; then
echo "Missing credentials";
exit 1;
fi
# Find public IP of hostname
IP=`dig +short $1`;
echo "ip: $IP";
# Find instance id from public ip
RF='.Reservations[0].Instances[0].InstanceId';
ID=`aws ec2 describe-instances --filter Name=ip-address,Values=$IP | jq -r $RF`;
echo "id: $ID";
# Get password data
DATA=`aws ec2 get-password-data --instance-id i-e716a211 | jq -r .PasswordData`;
# Decrypt password
KEY=~/.ssh/$SSH_KEY;
PWD=`echo "$DATA" | base64 -d | openssl rsautl -decrypt -inkey $KEY`;
echo "pass: $PWD"
# Launch desktop
rdesktop -u Administrator -p "$PWD" -KzDg 1920x1050 $1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment