SSH session never closes when executing "apt-get install"
The following answer on SF did the trick:
ssh fails to execute remote command when run from cron bash script
-t flag forces a pseudo-tty allocation, except perhaps when there is no TTY locally. But passing the flag twice like in
-t -t just pretends to do it. And that solved the problem.
See the SSH documentation:
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
Now, why did that work? It turns out that
debconf does not complain anymore about the frontend in the logs. So I believe that the double
-t sets (lures?)
debconf as needed, which allows
apt-get install completion to end the SSH session cleanly.