How to create a SSH Tunnel with ngrok on Ubuntu Server (aka ssh access to your local server in local network with dynamic ip)

I have a server at home running Ubuntu 18.04 LTS (normal local network, behind a router with firewall activated, no DMZ) and I wanted to be able to access it though ssh. You can think of it as a TeamViewer alternative for port redirection.

What’s SSH?

Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Typical applications include remote command-line login and remote command execution, but any network service can be secured with SSH. -Wikipedia

Enter grok

Public URLs for exposing your local web server. Spend more time programming. One command for an instant, secure URL to your localhost server through any NAT or firewall.

They weren’t kidding. To set it up do the following:

  1. Register at https://ngrok.com/
  2. Follow the steps on their “Getting started page”. There are 4 steps to follow. If you are in Ubuntu just run the following in the terminal to install. Both methods work just fine.

    sudo snap install ngrok

And then specify your auth token form here

ngrok authtoken your-token

3. Start ngrok on your ssh port. You can read more here

./ngrok tcp 22

4. Access your server with ssh

ssh  YOUR_USER@0.tcp.ngrok.io -p PORT

Where PORT is the port assigned by ngrok and YOUR_USER is your user in the server. You can also check the port assigned at your ngrok dashboard

Optional: copy your ssh key to your server for a password-less access

I use ssh-copy-id as follows

ssh-copy-id -p port -v 0.tcp.eu.ngrok.io -l user

You can read more about it here On Ubuntu ssh-copy-id is already installed. On Mac just run

brew install ssh-copy-id

For more details about brew, read here. In a few words, think of brew as a package manager for Mac (like snap, apt, rpm, etc…). If you just want to get it installed open a terminal window and run

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

About ngrok

ngrok is free for up to 10 devices. Their plans are in their pricing page

Their free plan allows the following:

  • HTTP/TCP tunnels on random URLs/ports
  • 1 online ngrok process
  • 4 tunnels/ngrok process
  • 40 connections / minute which is enough for personal and demo uses.

Enjoy!

Comments

Comments powered by Disqus