DEV Community

Shubhashish Dixit
Shubhashish Dixit

Posted on

How to access your laptop from anywhere in the WORLD without portforwarding!

Just think how awesome it'd be if you come to your home and see your laptop or any other resource up and working the way you want it to be.

Well that'd be pretty sweet if I get home and see my Spotify playlist playing on my speaker, my laptop up and working and loaded with the ongoing projects with all its virtual environments already loaded.

....all at the end of running a single script.

So get this, I live in a hostel right with a public shared wifi which clearly does not allow me fiddling around with its router settings. Of course, why would they :/

My only solution to get my little thing done is to expose my local web server to the internet.

(safe?! heck yeah!!, just a bit)

So how the heck do you do it anyway?!

One word answer: ngrok :)

Pre requisites needed:

Connect bot for android : download here

openssh for your laptop : sudo apt-get install openssh-server

Firewall people please remember that since we're going to be using port 22 for our little automation. We're gonna need to keep port 22 open. Please use ufw or uncomplicated firewall to open the port with

sudo ufw allow 22

Now hop on the train once again when you're done,
Follow along and setup your ubuntu or whatever os you are using. I am personally writing this article on zorin os which again is an ubuntu derivative.

  • Install ngrok from here
  • Follow along every step till authenticating your token.
  • FIRE IT UP!! with,
$ ./ngrok tcp 22

# now look for the line
Forwarding  tcp:// -> localhost:22

# the only thing useful to you is
# where XXXXX is your port number

(Completely Optional)

Hit the terminal again

Make some aliases for easiness with

alias ng="./ngrok tcp 22"

Now open connect bot and make a host

put in the very first line.

you can keep post login automation commands but I would not recommend those for then just again a personal preference of mine of if I ever need to do something before running the automated command.

you should get connected now.


Do I have to keep the command ./ngrok tcp 22 running?

Yes, sadly. So does the have to be your laptop and the ssh service.

Can't I Suspend my laptop?

No, you may not. Since that would stop the ssh service and of course other services. You may make it go to sleep put it charge and hit your way to life.

Do you and I have a very sad developer's life?

Yes, very!!

Will my port change every time I close the ngrok terminal?

Yes. Just change port number on the connect bot.

Thanks for Reading! ᕙ(⇀‸↼‶)ᕗ

Top comments (3)

codespent profile image
Patrick Hanford • Edited

This concept is also great for locally testing webhooks or any other functionality that requires your local development server to be accessible to the net!

./ngrok http 8000 will forward all requests from your ngrok url to Port 8000 so can then receive your webhook events locally!

amnemonic profile image
Adam Mnemonic

isn't this exactly port forwarding?

thisisshub profile image
Shubhashish Dixit

I do agree with you but to a certain level. In actual port forwading you have to set up dynamic DNS and keep playing with the router settings but with ngrok you don't port forward. It does :)

Thanks for the comment!