Skip to content

Instantly share code, notes, and snippets.

@awestendorf
Created March 18, 2019 18:42
Show Gist options
  • Save awestendorf/54a86a10928fc12a315ef6552b14985c to your computer and use it in GitHub Desktop.
Save awestendorf/54a86a10928fc12a315ef6552b14985c to your computer and use it in GitHub Desktop.
Put a local file on to a remote system using an SSH tunnel through a gateway
#!/bin/bash
# Fetch a file from a host in a datacenter. Example:
# ./put-file.sh my-datacenter my-host ~/local.file ~/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 $3 localhost:$4
kill $TUNNEL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment