SaltyCrane Blog — Notes on JavaScript and web development

How to run a Django local development server on a remote machine and access it in your browser on your local machine using SSH port forwarding

Here is how to run a Django local development server on a remote machine and access it in your browser on your local machine using SSH port forwarding. (This is useful if there is a firewall blocking access to the port of your Django local dev server (port 8000).

  1. On the local host, SSH to the remote host:
    $ ssh -v -L 9000:localhost:8000 [email protected] 
    
  2. On the remote host, run the Django dev server:
    [email protected]:/path/to/my/django/project$ python manage.py runserver 0.0.0.0:8000 
    
  3. On the local host, go to http://localhost:9000 in the browser

Note: The local port and the remote port can be the same (i.e. you can use 8000 instead of 9000). I just made them different to show which port is which.

Using LocalForward in your ~/.ssh/config

You can also achieve the same results by using the LocalForward in your ~/.ssh/config file:

Host myremote
  User eliot
  HostName my.remotehost.com
  LocalForward 9000 localhost:8000

Reference

http://magazine.redhat.com/2007/11/06/ssh-port-forwarding/

Comments


#1 jb0t commented on :

The cool thing about the config file is that you don't have to resort to using a .ssh/config. You can place the desired configs in any file then pass the -F configfile flag. I use this with -v and make a term window dedicated to the tunnels then I can see some info showing me that it's working properly.

In that config file you can create multiple directives. This is a really awesome way to forward lots of ports over a single ssh connection.

I dig your blog. Cheers!


#2 Mark commented on :

Very helpful, thanks!