Skip to content

Instantly share code, notes, and snippets.

@mike-carey
Created April 15, 2019 21:43
Show Gist options
  • Save mike-carey/f375cd6ffeb9dc92fab7db1c934853f4 to your computer and use it in GitHub Desktop.
Save mike-carey/f375cd6ffeb9dc92fab7db1c934853f4 to your computer and use it in GitHub Desktop.
Proxying HTTP through SSH Tunnel (As local http port)
---
version: '3'
services:
ssh_server:
image: mcareysolstice/ssh
ports:
- "2222:22"
volumes:
- ./id_rsa.pub:/root/.ssh/authorized_keys
http_server:
image: httpd:2.4
#!/usr/bin/env bash
# Create keys for authentication
ssh-keygen -f id_rsa -N '' -t rsa
# Start up the ssh server and an internal HTTP server
docker-compose up -d
# Bind the HTTP port over the SSH tunnel on a local port
ssh root@localhost -p 2222 -NC \
-L 1080:http_server:80 \
-i keys/id_rsa \
-o UserKnownHostsFile=/dev/null \
-o PasswordAuthentication=no \
-o StrictHostKeyChecking=no &
echo $! > ssh.pid
if hash open; then
open http://localhost:1080
else
echo "Please open a browser to http://localhost:1080"
fi
#!/usr/bin/env bash
# Kill the tunnel
kill -9 $(cat ssh.pid)
rm ssh.pid
# Stop the servers
docker-compose stop
# Remove the keys
rm id_rsa{,.pub}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment