Prerequisites:
- the device you're trying to access (behind NAT);
- a public SSH server (you need root access + custom sshd configuration to forward ports on 0.0.0.0, otherwise you can use jump hosts);
Setup steps:
- install
autossh
on the device behind nat; - generate a private ssh key pair to
/etc/ssh/id_autossh
; - authorize the public key on the public server (you may optionally create a limited account);
- create
/etc/systemd/system/autossh.service
and/etc/ssh/autossh.vars
and fill it with your specific setup variables; systemctl daemon-reload && systemctl restart autossh && systemctl enable autossh