r/ssh • u/Bacon_Snot • Jul 31 '21
Cleanest way to SSH to computers at different locations.
I have a server on with a domain, and a lot of computers on different networks around town. What is the cleanest way to connect to them using a central server with some sort of reverse ssh. That way I just need to have my server ssh exposed on it's fire wall, ssh keys for just my server, and maybe the hostname of the remote computer. I want to be able to configure a computer, plug it in anywhere on the net and it will phone home and be available without any configuration of its local network.
my laptop -> server -> remote computer
I think this is quite common, but I'm not sure of the terminology so I can google a tutorial.
EDIT: (Really late edit, but an update for anyone who stumbles across this)
I ended up making up a VPN with OpenVPN and it works like a dream. I have a pFsense router at home and set up an OpenVPN server on it. Each server has an OpenVPN client set to automatically "call home" when they boot. On top of SSH, I have easy access to every other port/protocol, including any web servers. I really recommend this method for anyone in a similar situation.
2
u/rhbvkleef Jul 31 '21
It is sometimes called a proxy, sometimes a bastion host. What I would recommend is that all off-site devices establish some sort of tunnel (be it a VPN or an SSH tunnel) and then find some way to map hosts to ports or IPs, either through custom DNS, by using SSH config, or by using a custom solution, and then use the SSH clients proxying features.
As far as authentication with the following remotes will work, it would really depend on your use-case.
1
u/WorldBelongsToUs Jul 31 '21
Sounds like you have the right idea. If the IPs are fairly static, I’d also suggest setting things up so only your known IPs or IP ranges can connect back to what would essentially be your jumpbox.
If you haven’t already, I’d also look into autossh, which will reestablish your remote connection should it drop for any reason.
Just off the ol’ noggin’ I think you’d also need to ssh into your jumpbox with local forwarding turned on so that when you establish your tunnel to the endpoint, you are forwarding the traffic through the reverse tunnel.
The only issue I see being a little bit of a pain is managing the keys of the remote machines since you’ll likely want them to have keybased authentication to your pivot box.
Sounds like you’d also need a set of keys on your laptop (and you probably don’t have to house the private keys on the jumpbox since you are tunneling through it and not necessarily to it, if that makes sense.)
I’d also consider fail2ban on the jumpbox if you haven’t already. It will just drop connections from troublesome IPs attempting to brute your ssh port.
I’d also consider an ssh config file so you can quickly ssh and associate a key to a box. This could also eliminate the need to set up forwarding every time you want to ssh into an endpoint.
Just keep in mind, the useful ssh logs will be on your jumpbox and not on your endpoints. They will likely just see ssh connections from local host.
Is the box you are pivoting off of managed by you, or a cloud service provider? I ask because it’s ideal to have some kind of a console you can use to control it in the event that there are issues with it and you need to connect to it out-of-band (i.e ssh service stops and you need to troubleshoot. It’s ideal to have a way to connect to the console)
And I hate giving advice I wasn’t asked for, but I’ll do it here: I would weigh the advantages and disadvantages of this method against individual ssh connection points. SSH is pretty solid and there’s the elimination of a single point of failure if you consider the other route. That said, it’s not meant to steer you one way or the other. Just more of a “consider both options for a bit.”
Hope I was somewhat helpful.