This project sets up a minimal EC2 instance for SSH tunneling/SOCKS proxy on AWS using Terraform.
- AWS CLI configured with credentials
- Terraform installed
- SSH key pair created locally (
ssh-keygen -t rsa)
# Copy and configure variables
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your values# Initialize Terraform
terraform init
# Review the deployment plan
terraform plan
# Deploy the infrastructure
terraform apply# Get the server IP from Terraform output
SERVER_IP=$(terraform output -raw proxy_server_public_ip)
# Create SOCKS proxy on port 8080
ssh -D 8080 -N ubuntu@$SERVER_IPConfigure your browser to use localhost:8080 as a SOCKS5 proxy:
Chrome/Chromium:
# Launch Chrome with proxy
google-chrome --proxy-server="socks5://localhost:8080"Firefox:
- Settings > Network Settings > Manual proxy configuration
- SOCKS Host:
localhost, Port:8080, SOCKS v5
Safari:
- System Preferences > Network > Advanced > Proxies
- Check "SOCKS Proxy", enter
localhost:8080
main.tf- Terraform infrastructure configurationterraform.tfvars.example- Example Terraform variables
# Get server IP
SERVER_IP=$(terraform output -raw proxy_server_public_ip)
# Start tunnel (runs in foreground)
ssh -D 8080 -N ubuntu@$SERVER_IP
# Or run in background
ssh -D 8080 -N -f ubuntu@$SERVER_IP# Check your IP without proxy
curl ifconfig.me
# Check your IP through proxy
curl --socks5 localhost:8080 ifconfig.me# Find the SSH process
ps aux | grep "ssh -D 8080"
# Kill the process
kill <PID># Use proxy with curl
curl --socks5 localhost:8080 https://example.com
# Use proxy with wget
wget -e use_proxy=yes -e https_proxy=socks5://localhost:8080 https://example.com- Your real IP: Your home/office IP address
- Proxy IP: Your EC2 instance IP in US West
- Websites see: EC2 instance location (US West)
- Traffic encrypted: Between you and EC2 instance
- Bypasses: Geographic restrictions, some firewalls
terraform destroy- Change
allowed_ssh_cidrin terraform.tfvars to restrict SSH access to your IP - The server only allows SSH (port 22) - no additional ports opened
- All proxy traffic goes through encrypted SSH tunnel
- t3.micro instance: ~$8.50/month (free tier eligible for 12 months)
- Data transfer: $0.09/GB for first 100GB/month
- Total for light usage: ~$10-15/month
# Test SSH connection
ssh ubuntu@$(terraform output -raw proxy_server_public_ip)# Check if tunnel is running
ps aux | grep "ssh -D"
# Test proxy connection
curl --socks5 localhost:8080 ifconfig.me- Make sure your browser/app is configured to use the SOCKS5 proxy
- Check proxy settings:
localhost:8080, protocol: SOCKS5