sudo raspi-config
apt install autossh vim
Install AutoSSH on a remote_host to connect to a local_host to allow connections from this local_host or any_host from any (other) location.
remote_host$ ssh -R <port_to_access_remote_from_local>:localhost:22 user@<domain_name_of_local_host> -p <ssh_port_local_host>
[Unit] Description=AutoSSH tunnel service Remote port <port_to_access_remote_from_local> to local 22 After=network.target [Service] Environment="AUTOSSH_GATETIME=0" ExecStart=/usr/bin/autossh -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -N -R <port_to_access_remote_from_local>:localhost:22 user@<domain_name_of_local_host> -p <ssh_port_local_host> -i /home/pi/.ssh/id_ecdsa [Install] WantedBy=multi-user.target
We need to tell SSH the identity file as systemd will run as root. The environment variable is added so the autossh service can run in the background.
remote_host$ sudo systemctl daemon-reload remote_host$ sudo systemctl start autossh-tunnel.service remote_host$ sudo systemctl enable autossh-tunnel.service
sudo journalctl -u autossh-tunnel.service [-b]
local_host$ ssh pi@localhost -p <port_to_access_remote_from_local>
Connections from any location cannot tunnel to other services on the remote network directly. Instead, we can open a (temporary) tunnel to any host on the remote network and add a tunnel to the same port to the connection from any_host to local_host.
remote_host$ ssh -R <port_to_access_additional_service>:host_on_remote_network:<port_to_additional_service> user@<domain_name_of_local_host> -p <ssh_port_local_host>