Determining the port assigned by -R 0

Glenn Maynard glenn at
Sat Oct 15 07:55:55 EST 2011

It's difficult to programmatically determine the port dynamically assigned
by -R 0.  The port is output in plain (and presumably localized) text, but
I've found that by far the most common use of this is for scripts.

Is there currently any sane way to get this information?  For the short term
I'll probably just parse the plaintext "Allocated port..." message, but
that's obviously not a reliable solution.  It would be helpful if a list of
forwarded ports was stored in a parsable environment variable, as with

Glenn Maynard

More information about the openssh-unix-dev mailing list