I have two systems: An Ubuntu 20.04 server on the Internet and a Raspberry Pi 2B (Ubuntu 18.04) in my local LAN (behind a NAT router). I am opening a reverse tunnel from the Raspberry Pi to the server like so:
ssh -f -N -R 13333:127.0.0.1:22 server
The config file looks like:
Host server Hostname <public IP> User serveruser IdentityFile /home/piuser/.ssh/serverkey
Then on the server I am running the following command:
ssh -p13333 -i ~/.ssh/pikey email@example.com
For the pikey, a command is executed on the Raspberry (set in the authorized_keys file).
I tried this setup a few times yesterday, but today (~24h later) I couldn't use the tunnel anymore.
ss showed me the open ports, and I was able to execute the command on the server, but there was no response- the command just "hung".
Then, I killed the tunnel and re-established it, without any problem. To troubleshoot the problem more, I added -vvv to the command sent from the server:
ssh -vvv -p13333 -i ~/.ssh/pikey firstname.lastname@example.org
This showed me the stuck connection at the following point:
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020 debug1: Reading configuration data /home/serveruser/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug2: resolve_canonicalize: hostname 127.0.0.1 is address debug2: ssh_connect_direct debug1: Connecting to 127.0.0.1 [127.0.0.1] port 13333. debug1: Connection established. debug1: identity file /home/serveruser/.ssh/pikey type 0 debug1: identity file /home/serveruser/.ssh/pikey-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
This time, on the site of the Raspberry Pi I saw:
$ Warning: remote port forwarding failed for listen port
So my last try was rebooting the Raspberry, and, voila after establishing the tunnel again, it worked as it's supposed to work.
Finally, my question: How can I determine what went wrong? I rely on that connection when abroad, so I really need to figure out what went wrong and how I can fix that...
Btw, I Googled a bit, but none of the suggestions / solutions work for my case, since I was able to establish the connection in the first place, but some hickup brought it into a strange state.
If you need anymore information, please let me know :)