I've answered your question below, but before I do...
I'll start by saying it sounds like you are implementing some kind of IOT device. In this context it's a little unidiomatic to want an SSH connection. This can work with tens or even hundreds of customers. But it will rapidly become unmanageable.
Usually you should:
- Deploy your OS upgrades as complete images... so no remote calls to
apt-get dist-upgrade
which can brick the device and force you to send an engineer to fix them.
- Deploy your application in a similar manner, sending it as one complete package which self-deploys.
- Consider tools similar to Puppet which can carry out maintenance unassisted and give a way to send the same upgrades to may devices simultaneously.
Having worked in this space with ~3,000 devices you really don't want to get in the habit of logging in via SSH if you can possibly avoid it.
Always consider security. If this opens up a hole for a hacker to get onto user's home network then it can end your business.
If dialling in through SSH is your only option then you have a few options.
Reverse SSH tunnel
You can configure the device to ssh into a remote server with a port forwarding back to port 22
on the device. Typically you do this on-demand, so include some trigger in your own software which tells it to do this.
The device would need to be told a "remote" port to use, and you would then need to know what that port is. So if the remote port was 1234
, the device would dial out to your server:
ssh -R 1234:localhost:22 remote-server.example.com
You can then, yourself SSH into the remote server and from the server SSH onto the IOT device using the remote port previously mentioned:
ssh -p 1234 localhost
This is a bit convoluted but it works. You are making an SSH connection which is wrapped in an ssh connection. But it works!
Permanently attached VPN
As you mention you can setup a VPN server. I would avoid this server having any access to your own network.
You can find examples on the web for OpenVPN which will most likely be the right VPN technology for this situation. There's a couple of "gotyas" to avoid:
- Users do crack into own devices. You can't entirely stop that.
- You don't want to give your users access to snoop round your corporate network. Don't give your VPN server access to anything on your corporate network, make it standalone.
- Don't enable OpenVPN's
--client-to-client
communication. Would let clients talk to each other which you don't want. However you will then need to consider how to use this VPN? Initiating SSH connections from the server will be fine. Otherwise how will you connect your laptop to the server such that it isn't a VPN client.
- Make sure you have read up on "auto reconnect". VPNs drop disconnect without warning and the client will need to reconnect automatically.
UPnP
Most / All home routers support Universal Plug and Play. This would let your IOT device open a port on the user's home router letting you dial in directly.
This does work, but remember that some users disable this feature as they feel it is a security risk. Eg: blog discussion on the topic here.
ssh
to create a tunnel from the device through the router to a public server you control. You can then use that tunnel to access the device. – Panki Aug 12 '21 at 08:45