Created
February 8, 2017 06:38
-
-
Save knksmith57/4bb8036eb8c65ff15c36f885341cdeea to your computer and use it in GitHub Desktop.
Revisions
-
knksmith57 created this gist
Feb 8, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #!/usr/bin/env bash -e instance_name="throw-away-$(date +%s)" region=us-west1-b ssh_key_dir="$(mktemp -d)" cleanup() { echo "removing temp dir: $ssh_key_dir" rm -rf "$ssh_key_dir" echo "killing instance" gcloud compute instances delete --zone us-west1-b --quiet $instance_name } trap cleanup EXIT echo "generating ssh key pair in: $ssh_key_dir" ssh-keygen -t rsa -b 4096 -C '' -N '' -f "$ssh_key_dir/id_rsa" &>/dev/null pub_key="$(< "$ssh_key_dir/id_rsa.pub")" echo "creating instance: $instance_name" gcloud compute instances create $instance_name \ --zone $region \ --machine-type f1-micro \ --metadata "ssh-keys=foobar:$pub_key" \ --maintenance-policy TERMINATE \ --image debian-8-jessie-v20170124 \ --image-project debian-cloud \ --boot-disk-size 10 echo "discovering instance IP address" ip_address="$(\ gcloud compute instances describe $instance_name \ --zone $region \ --format json \ | jq -r .networkInterfaces[].accessConfigs[].natIP \ )" echo "creating SOCKS5 tunnel from localhost:5555 => $ip_address" ssh -D 5555 -C -q -N \ -i "$ssh_key_dir/id_rsa" \ -o StrictHostKeyChecking=no \ foobar@$ip_address