How to know when the listening socket is ready

R. Diez rdiez-2006 at rd10.de
Mon Mar 30 06:57:40 AEDT 2026


>> One problem I have with 'ssh' is knowing when the tunnel is ready. If use-the-tunnel.sh tries to connect immediately, it will probably fail, as 'ssh' needs some time. How long it needs depends on the weather.

> Would that be a good case for LocalCommand?  If you launch the shell script that way, it will only happen after the login is successful.

Thanks for your feedback. LocalCommand does work. I am using it to run "systemd-notify --ready", which does the trick for my systemd unit.

There is some confusion about LocalCommand though. It is not documented whether LocalCommand runs before or after creating the listening socket for the tunnel. I haven't seen any failures yet, so it seems to be afterwards (which is what I would expect).

The documentation states it runs "when the ssh connection has been established", but somebody here said "before the ssh session is established":

https://serverfault.com/questions/640920/run-local-command-after-ssh-session-ends

Fortunately, whether the "SSH session", whatever that is, has been setup or not does not affect my usage scenario (a TCP tunnel).

Best regards,
   rdiez


More information about the openssh-unix-dev mailing list