SaltyCrane Blog —  Notes on Python and web development on Ubuntu Linux

How to expose a Flask local development server to the public using SSH remote port forwarding

Here is how to run a Flask local development server on your local machine and expose it to the public via a remote server you have control over. This uses SSH remote port forwarding which is a converse of local port forwarding described here: 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

  1. On the remote host, edit the sshd_config file (mine was located at /etc/ssh/sshd_config) to allow remote hosts to connect to ports forwarded for the client:
    GatewayPorts yes
  2. On the remote host, restart the SSH server:
    $ sudo service sshd restart 
  3. On the local host, SSH to the remote host:
    $ ssh -v -R 50051:localhost:5000 
  4. On the local host, run the Flask dev server:
    $ python localhost 5000 
  5. Go to in the browser

Using RemoteForward in your ~/.ssh/config

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

Host myremote
  User eliot
  RemoteForward 50051 localhost:5000


See also

localtunnel by Jeff Lindsay exposes your local development server without requiring a public remote server.

2 Comments — feed icon Comments feed for this post

#1 John Sheehan commented on 2014-02-14:

There are a bunch of good services that will do this more easily as well:

#2 Eliot commented on 2014-02-14:

John, thanks for the great list. I'll remember that for the future. At the time I needed this, I actually was trying to expose my dev server at a specific URL that a third server was pointing at. I know my post fails to mention that.

Post a comment

Required, but not displayed

Format using Markdown. (No HTML.)
  • Code blocks: prefix each line by at least 4 spaces or 1 tab (and a blank line before and after)
  • Code span: surround with backticks
  • Blockquotes: prefix lines to be quoted with >
  • Links: <URL>
  • Links w/ description: [description](URL)
Created with Django and Bootstrap | Hosted by Linode