Skip to content

Instantly share code, notes, and snippets.

@vyach-vasiliev
Forked from mhulse/ssh tunneling.md
Created September 15, 2020 10:53
Show Gist options
  • Save vyach-vasiliev/5f469123367cbc8e73c1fb1fe4447dca to your computer and use it in GitHub Desktop.
Save vyach-vasiliev/5f469123367cbc8e73c1fb1fe4447dca to your computer and use it in GitHub Desktop.
SSH Tunneling: Map port from remote machine to your local machine so you can work from the remote DB (example using Django DB settings)...

SSH Tunneling

  1. In your local_settings.py file:

    DATABASES = {
    	'default': {
    		'ENGINE': 'django.db.backends.postgresql_psycopg2',
    		'NAME': 'django_%s' % (PROJECT_NAME,),
    		'USER': xxxx,
    		'PASSWORD': xxxx,
    		'HOST': 'localhost',
    		'PORT': '1234',
    	}
    }
    
  2. SSH to development server.

    To connect to the production server, from the command line, run:

    $ ssh -N -L 1234:localhost:5432 remote.com

    • 1234 = local port
    • 5432 = remote port

    Important: Don't close shell window.

    Note: After entering the above command, you won't get any feedback until you exit.

  3. You might need to $ touch your wsgi file or restart Apache (Django development server restarts automatically).