How to avoid "Connection to <host> closed" with -t? - SSH

This is a discussion on How to avoid "Connection to <host> closed" with -t? - SSH ; When you ssh to a host specifying a command but no -t it shows only the command output: $ ssh myhost date me@myhost's password: Thu Jan 4 19:25:11 PST 2007 $ But if you specify -t (to allocate a pseudo-TTY) ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: How to avoid "Connection to <host> closed" with -t?

  1. How to avoid "Connection to <host> closed" with -t?

    When you ssh to a host specifying a command but no -t it shows only the
    command output:

    $ ssh myhost date
    me@myhost's password:
    Thu Jan 4 19:25:11 PST 2007
    $

    But if you specify -t (to allocate a pseudo-TTY) it prints a "Connection
    to closed" message after the command output:

    $ ssh -t myhost date
    me@myhost's password:
    Thu Jan 4 19:25:16 PST 2007
    Connection to myhost closed.
    $

    This is using OpenSSH (client 4.0p1, server 3.9p1), BTW.

    So: is there any way to prevent ssh from printing the "Connection to
    closed" message when using -t?

    - John

  2. Re: How to avoid "Connection to <host> closed" with -t?

    In article John
    Caruso writes:
    >When you ssh to a host specifying a command but no -t it shows only the
    >command output:
    >
    > $ ssh myhost date
    > me@myhost's password:
    > Thu Jan 4 19:25:11 PST 2007
    > $
    >
    >But if you specify -t (to allocate a pseudo-TTY) it prints a "Connection
    >to closed" message after the command output:
    >
    > $ ssh -t myhost date
    > me@myhost's password:
    > Thu Jan 4 19:25:16 PST 2007
    > Connection to myhost closed.
    > $
    >
    >This is using OpenSSH (client 4.0p1, server 3.9p1), BTW.
    >
    >So: is there any way to prevent ssh from printing the "Connection to
    >closed" message when using -t?


    From looking at the source (and verified by testing), it can be found
    that you can turn that message (and probably others) off by including
    '-o LogLevel=QUIET' on the command line. However I think this behaviour
    is quite broken - the printing of the message should not be dependant on
    pty allocation, but on whether interactive mode is being used. I.e. it
    should be printed only when you didn't specify a 'command' (or subsystem
    via -s) on the command line. Even if these things go hand-in-hand *by
    default*, the availability of both -t and -T means that they are
    actually quite orthogonal. I think a bug report would be appropriate.

    --Per Hedeland
    per@hedeland.org

  3. Re: How to avoid "Connection to <host> closed" with -t?

    >>>>> "PH" == Per Hedeland writes:

    PH> In article
    PH> John Caruso writes:
    >> When you ssh to a host specifying a command but no -t it shows only
    >> the command output:
    >>
    >> $ ssh myhost date me@myhost's password: Thu Jan 4 19:25:11 PST 2007
    >> $
    >>
    >> But if you specify -t (to allocate a pseudo-TTY) it prints a
    >> "Connection to closed" message after the command output:
    >>
    >> $ ssh -t myhost date me@myhost's password: Thu Jan 4 19:25:16 PST
    >> 2007 Connection to myhost closed. $
    >>
    >> This is using OpenSSH (client 4.0p1, server 3.9p1), BTW.
    >>
    >> So: is there any way to prevent ssh from printing the "Connection
    >> to closed" message when using -t?


    PH> From looking at the source (and verified by testing), it can be
    PH> found that you can turn that message (and probably others) off by
    PH> including '-o LogLevel=QUIET' on the command line.

    Or simply ssh -q.

    --
    Richard Silverman
    res@qoxp.net


  4. Re: How to avoid "Connection to <host> closed" with -t?

    On 2007-01-05, Per Hedeland wrote:
    >>So: is there any way to prevent ssh from printing the "Connection to
    >>closed" message when using -t?

    >
    > From looking at the source (and verified by testing), it can be found
    > that you can turn that message (and probably others) off by including
    > '-o LogLevel=QUIET' on the command line.


    Yes, that works, thanks--though it's undesirable because it suppresses
    important messages in addition to "Connection to closed."

    > However I think this behaviour
    > is quite broken - the printing of the message should not be dependant on
    > pty allocation, but on whether interactive mode is being used. [...]
    > I think a bug report would be appropriate.


    I agree: http://bugzilla.mindrot.org/show_bug.cgi?id=1273

    However, in looking through the code (which I should have done in the first
    place), the association between pty allocation and "interactive mode" is
    pretty deep--they're essentially treated interchangeably. E.g.:

    /* No command specified - execute shell on a tty. */
    tty_flag = 1;

    And:

    if (buffer_len(&command) == 0)
    tty_flag = 1;

    And:

    if (tty_flag) {
    [...]
    interactive = 1;
    have_tty = 1;

    So this bug may not be as easy to fix as it might seem at first blush.

    - John

+ Reply to Thread