Serveo, SSH, and local web servers.

 Here are some "cheat codes" or helpful commands and tips for working with Serveo, SSH, and local web servers. These commands will help you streamline your development process and take advantage of the tools you're working with.

1. Basic Serveo Command:

This command establishes a reverse SSH tunnel to expose your local server to the internet.

ssh -R 80:localhost:80 serveo.net
  • Explanation:
    • -R 80:localhost:80: This tells Serveo to listen on port 80 of their remote server and forward requests to localhost:80 (your local machine's web server).
    • serveo.net: Connects to Serveo’s server to establish the tunnel.

2. Custom Subdomain on Serveo:

If you want a custom subdomain for your Serveo URL, you can specify one like this:


ssh -R mycustomsubdomain.serveo.net:80:localhost:80 serveo.net
  • Example: This will give you a public URL like https://mycustomsubdomain.serveo.net.

3. Expose Specific Ports Other Than 80 (HTTP):

If your server is running on a different port (e.g., 3000 for Node.js or Spring Boot), you can specify that port in the Serveo command:

ssh -R 80:localhost:3000 serveo.net
  • Explanation: This forwards requests on port 80 of the Serveo server to port 3000 on your local machine.

4. Keep Your SSH Tunnel Alive:

By default, SSH sessions can time out if idle for too long. To prevent this from happening, you can add these options to keep the session alive:


ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -R 80:localhost:80 serveo.net
  • Explanation:
    • ServerAliveInterval=60: Sends a "keep-alive" signal every 60 seconds.
    • ServerAliveCountMax=5: Allows up to 5 missed "keep-alive" signals before disconnecting.

5. Reverse SSH Tunnel for Multiple Local Services:

If you want to expose multiple services (e.g., a web server on port 80 and a database on port 3306), you can use the following:

ssh -R 80:localhost:80 -R 3306:localhost:3306 serveo.net
  • Explanation: This command exposes both your local HTTP server on port 80 and a MySQL database on port 3306 via the Serveo tunnel.

6. Expose a Local Application Behind a Proxy (e.g., Docker or VMs):

If you have your application running in Docker or a virtual machine (VM), you can expose it through Serveo by mapping the right port to the local service:

ssh -R 80:localhost:8080 serveo.net
  • Explanation: If your app is running in Docker on port 8080, you can expose it via Serveo's remote 80 port.

7. Automatic Restart of Serveo Tunnel (using tmux or screen):

If you want to make sure your SSH tunnel continues to run even after closing the terminal, you can use tools like tmux or screen:


tmux ssh -R 80:localhost:80 serveo.net
  • Explanation: tmux will keep your session running even after you close the terminal. You can always reconnect to the session later.

8. Troubleshooting Serveo Tunnel Issues:

If your tunnel is not working as expected, check these things:

  • Verify Port Binding: Ensure the local port (e.g., localhost:80) is not blocked by a firewall or another application.
  • Check Server Response: Use curl to check the response from your local server:

    curl http://localhost:80
  • Verify Public URL Access: If your local server works fine but the Serveo URL does not, verify the tunnel is still open and running in your terminal. Re-run the ssh command if necessary.

9. Access Web UI of SSH Sessions (Web Console for SSH):

Some SSH providers like Serveo might allow you to view your session output in a web UI. If you're looking to view logs or status, it's useful to have a tail command running to monitor logs in real-time:


tail -f /var/log/apache2/access.log
  • Explanation: This shows the real-time access logs of your Apache web server, so you can see what requests are coming in.

10. Expose a Specific Local Page Instead of Entire Server:

If you only want to expose a specific local page (like a dashboard) rather than the entire server, you can use a proxy server locally to route that specific page. For example, using nginx:


# Example nginx config server { listen 80; server_name localhost; location /dashboard { root /path/to/dashboard/folder; index index.html; } }

Then use the same Serveo command to expose it.

Ranjit Patil

Ranjit is a passionate engineer specializing in AI/ML, Java, and Spring Boot. He loves talking about technology and is endlessly curious about the creation of the universe.

1 Comments

comment here

  1. Keep the Tunnel Running

    As long as the SSH session is open, your local server will remain accessible via the public Serveo URL. If the session closes (e.g., you close the terminal), the tunnel will stop, and the URL will no longer be available.

    If you want to keep it running in the background, you can use the -f flag with the SSH command:

    ssh -f -N -R mysubdomain.serveo.net:80:localhost:5500 serveo.net

    This command runs Serveo in the background (-f) and doesn’t execute any remote commands (-N).

    ReplyDelete
Previous Post Next Post