Skip to content

Instantly share code, notes, and snippets.

@awestendorf
Created March 18, 2019 18:38
Show Gist options
  • Save awestendorf/392812ee9f2694148331606a3466570c to your computer and use it in GitHub Desktop.
Save awestendorf/392812ee9f2694148331606a3466570c to your computer and use it in GitHub Desktop.
Get a file off a remote system using an SSH tunnel through a gateway
#!/bin/bash
# Fetch a file from a host in a datacenter. Example:
# ./get-file.sh my-datacenter my-host ~/my.file
# spawn tunnel
ssh -n -t -t -L 22000:$2:22 $1 &
TUNNEL=$!
sleep 5
# need to turn off host checking because localhost:22000 will change as
# you connect to different datacenters
scp -r -P 22000 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no localhost:$3 ./
kill $TUNNEL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment