recover ssh session connection

Solution 1:

You want a persistent terminal multiplexer, such as tmux or GNU screen.

These allow you to open one or more shell sessions within a single connection; detach from them (either deliberately, say at the end of your workday, or unintentionally, as due to network problems) and later reconnect to the same shell session(s).

There are many subcommands and possible customizations, but a typical use would be as

$ tmux      /* starts new shell, with tmux status bar at the bottom of terminal window */
$           /* do stuff */
$ Ctrl-b d  /* key escape sequence to detach from tmux session */
$ exit

            /* ... time passes; much later you ssh back in ... */

$ tmux attach

            /* and you're back on the session you detached from */

As an additional note, while I provided links to the project webpages, both options are packaged for ubuntu and can be installed via sudo apt install, if not already installed on whichever OS version you are running.