A quick way to access your local server on the internet
Gbenga Kusade
Posted on December 14, 2023
Sometimes you may need to test and market your locally hosted applications on the internet while developing in a local environment. Having a tool that allows you to create a tunnel between your local development environment and a remote server using some tunneling services that enables you to share your work, test and deploy hosted application without the need for public infrastructure comes in handy here.
You'll see how to quickly access your local webserver over the internet using Localhost.run in this tutorial.
Localhost.run
Using localhost.run is as simple as running the following ssh command in your terminal to connect an internet domain to an application running locally on port 8080
ssh -R 80:localhost:8080 ssh.localhost.run
you will be presented with the following similar output
Scan the QR code with your mobile and your local server will be accessible in your phone browser.
There are instances you can receive permission denied error due to some ssh key issue, to fix, do the following:
1. change directory to the current user home directory
Cd ~
2. Check if "id_dsa.pub" file exist in your ".ssh" folder
3. If exist, skip to step 5. if not, run ssh-keygen command to generate a public ssh key:
ssh-keygen
4. Follow the screen prompt until the key is generated
5. Add the generated public key to the authorized_key file, which contains public keys for public key authentication:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
6. Run localhost.run command again:
ssh -R 80:localhost:8080 ssh.localhost.run
While this may seem like a straightforward approach, the free version is however time limited, and may not be suitable if you need to stay longer using it. You will need to create an account to stay longer.
Other services providing similar function include:
-
Ngrok: This provides about 2hours on the free account but requires account registration and adding your authtoken, and starting it is as simple as running
ngrok http 8080
Cloudflare Tunnel: requires account registration
Note
Please know that following this tutorial may introduce a potential for reduced security and privacy. So, use cautiously!
References
Posted on December 14, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.