I've been using Nextcloud on my LAN. It is provisioned to only be used on the LAN.
For the first time in a long while, I'm away visiting relatives. I wanted to access the Nextcloud app, but since it's only accessible from the LAN, I thought I'd not be able to access it from another state without jumping through some hoops. I was wrong.
Now, I've done this before but it's been like 15 years and I was initially super rusty with this: I wanted to try to access the Nextcloud console by establishing an SSH tunnel.
I've one machine that has port 22 exposed to the internet (using SSH key authentication - yeah, I'm not totally aloof). That machine is a Mac Mini - it is functioning as an SSH jumphost. The Mac Mini can talk to the machine that is hosting a Docker instance of Nextcloud. The Nexcloud console is mapped to port 1234 and is accessible using HTTP.
How did I establish a connection?
The public address to my LAN is 203.0.113.25. The Mac Mini's IP is 192.168.1.200. The Nextcloud IP is 192.168.1.22 (listening on port 1234).
All of the IP info is fictional for this exercise. To get this to work with your systems, change the IPs to match the hosts of your systems.
I ran the following:
ssh -L 1234:192.168.1.22:1234 ron@203.0.113.25
The above runs in the foreground (it establishes an active shell connection)
ssh -f -N -L 1234:192.168.1.22:1234 ron@203.0.113.25
The above runs in the background (it prompts you for login creds or key authentication, and nothing else)
Then, open a browser and type: http://localhost:1234
Using the above-mentioned steps, I was able to access the Nexcloud console using a browser client. Not only that, Nexcloud has an agent client. I pointed that to http://localhost:1234 and it connected!
To better script this process, you can also add the following to your SSH config:
Host home
HostName YOUR_PUBLIC_IP
User username
LocalForward 1234 192.168.1.22:1234
And then run the following command:
ssh home
Needless to say, if you've SSH exposed to the internet, you should use key-based authentication and disable password authentication. As well, I recommend some type of rate-limiting, as you're going to see a crapload of bots attempting brute force authentication against your exposed SSH port (I use fail2ban). Using a non-standard port to serve SSH connections is also an option, as most bots tend to only look for port 22 (note that this is considered to be obscuring, which is not really making anything secure).
This example is also for my Nextcloud setup but can be used for anything. For example, I can use it to access my Portainer console on my Docker host. I can use it to access other hosts on the LAN besides the Docker host system, as well. Anything goes.
This isn't really anything super revealing...folks have been doing this for years in corporate IT and home. I just thought it would be cool to share something that could help some folks that have never done such a thing. Have fun with it!
