Hi everyone, so I’m new to selfhosting and I have a tiny problem. I’ve got a VPS up and running, I want to connecet to Hotspot Shield VPN from the VPS. I currently login to the server with ssh. When I connect to hotspotshield from command line, I think it connects. I only say that because my ssh connection terminates. I suppose it’s because the VPN is connected and the ip is changed and stuff. I wonder how you guys connect to VPN without breaking your connection with the server.
Well, first of all, I’m not sure about the reputation of Hotspot Shield, so I would recommend you getting a proper VPN instead. But that’s not your question, so I won’t go too much into it.
When you connect your VPS to the VPN, your established SSH connection before the VPN connection gets cut off because now your VPS sends everything through the VPN instead of directly to you. There are two solutions to it:
- Don’t connect everything to the VPN.
Currently, once you connect to the VPN, everything from the VPS goes through it. The easiest way to get around this and probably the way most people use is to convert your workflow into Docker/Podman containers. By doing this, only the container’s networking is tunneled through the VPN, and other network traffic from your host is not. For the other applications that you want them to go through the VPN, you could again use containers, and make it that they use the networking stack from the VPN container, so their traffic goes through the VPN too. This way, only traffic for the selected containers go through the VPN, and you can connect to the host via SSH directly.
You can also skip all these by just using iptables to force your SSH traffic out of the tunnel, but that’s much more advanced.
- Use Cloudflare Tunnel
With Cloudflare Tunnel, you could set up that your VPS is always connected to Cloudflare as long as it has an internet connection, and you connect to your VPS via SSH through Cloudflare. More information here
- Port forwarding from your VPN provider
You could also ask your VPN provider to open a port for your VPS, and then you could forward the port to your VPS’ SSH port, then you can connect to your VPS via SSH with the VPN’S IP and the opened port.
After digging a little deeper I found this