# Long-running Persistent Tunnels

> Persistent tunnels with Pinggy: Host sites and apps hassle-free from localhost. Get a subdomain, generate SSH key, and enjoy uninterrupted hosting.
> Source: https://pinggy.io/docs/guides/long_running_tunnels/


# Long-running Persistent Tunnels

You can use Pinggy to host websites, apps, and files from localhost just like any server. You just need to ensure the following:

1. Get a persistent subdomain or a custom domain from the <a href="https://dashboard.pinggy.io" target="_blank">dashboard</a>.
2. To generate an SSH key, run the following command in your terminal and press Enter:

   ```bash
ssh-keygen
```

   Press Enter to save the key in the default location, optionally add a passphrase by typing it and pressing Enter, and continue pressing Enter for any additional prompts until the command finishes.

3. Use the token to start the tunnel as described next.

   The following command ensures that your tunnels stay alive and restart on its own if something goes wrong:

   
#### CLI

<p>Pinggy CLI has auto reconnection built in. Download the Pinggy CLI from <a href="/cli/" target="_blank">here</a> and run the following command:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">./pinggy -p <span class="m">443</span> -R0:localhost:8000 &lt;token&gt;@pro.pinggy.io
</span></span></code></pre></div>

#### SSH

<p>In <strong>Mac OS</strong> or <strong>Linux</strong>, use the following script to enable auto reconnection.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># pinggy.sh</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">while</span> true<span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="k">do</span> ssh -p <span class="m">443</span> -o <span class="nv">ServerAliveInterval</span><span class="o">=</span><span class="m">60</span> -R0:localhost:8000 &lt;token&gt;@pro.pinggy.io<span class="p">;</span>
</span></span><span class="line"><span class="cl">    sleep 2<span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="k">done</span>
</span></span></code></pre></div><br/>
<p>For <strong>Windows</strong>, use the following script:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">  <span class="c1"># pinggy.bat</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  FOR /L %N IN <span class="o">()</span> DO ssh -p <span class="m">443</span> -o <span class="nv">ServerAliveInterval</span><span class="o">=</span><span class="m">60</span> -R0:localhost:8000 &lt;token&gt;@pro.pinggy.io
</span></span></code></pre></div>



   Replace `8000` with the port you want to share, and `token` with your tunnel token.

