You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "towsb1 (via GitHub)" <gi...@apache.org> on 2026/04/01 18:09:22 UTC
[I] All output echoed back on input on a ChannelShell [mina-sshd]
towsb1 opened a new issue, #893:
URL: https://github.com/apache/mina-sshd/issues/893
### Version
2.16.0
### Bug description
Using a ChannelShell to manage the connection, anything written out to an SSH server (`ChannelShell.getInvertedIn()`) gets echoed back on the input stream (`ChannelShell.getInvertedOut()`). Connecting to the exact same servers with a jsch SSH implementation does not have any output echo, so its definitely not a server configuration problem.
### Actual behavior
I've tried disabling all echo flags in the PtyMode:
```
HashMap<PtyMode, Integer> ptyModes = new HashMap<>();
ptyModes.put(PtyMode.ECHO, 0);
ptyModes.put(PtyMode.ECHOE, 0);
ptyModes.put(PtyMode.ECHOK, 0);
ptyModes.put(PtyMode.ECHONL, 0);
channel.setPtyModes(ptyModes);
```
Also tried disabling agent forwarding via `ChannelShell.setAgentForwarding(false)` (even though this function has no javadoc and I have no idea what it might actually do).
At this point I can only surmise there's something else going on that needs to be examined to prevent output echo.
### Expected behavior
Setting echo flags to 0 should disable output echo, or some other setting needs to be made available to generally stop output from being echoed back on the input stream.
### Relevant log output
```Shell
```
### Other information
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "tomaswolf (via GitHub)" <gi...@apache.org>.
tomaswolf commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4174890661
Could you please provide a minimal example (source code) showing the problem?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "tomaswolf (via GitHub)" <gi...@apache.org>.
tomaswolf commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4195538102
Looks like you're connecting to some device (that would respond with a "cli>" prompt). Since I don't have that device, I won't be able to reproduce this.
So I can do only code inspection... Only thing that looks a bit strange it that `channel.setRedirectErrorStream(true)`. Can you show the client code using JSch, too? Does the JSch code do that, too, and output the server's stderr on stdout?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "towsb1 (via GitHub)" <gi...@apache.org>.
towsb1 commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4247256250
I've managed to repeat this with the TRACE logging on. I don't want to post the whole log out of security concerns for the server I'm connecting to, but this is the section immediately after the `cli>` prompt comes in. Is this showing the "shell" part that this test sends is actually being read back on the input stream direct from the device? Not sure exactly how to read some of this.
```
<-
cli>
[main] DEBUG org.apache.sshd.common.channel.RemoteWindow - waitForSpace(RemoteWindow[client](ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922])) available: 2097152
[main] TRACE org.apache.sshd.client.channel.ChannelShell - flush(ChannelOutputStream[ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]] SSH_MSG_CHANNEL_DATA) len=6, available=2097152
[main] DEBUG org.apache.sshd.common.channel.RemoteWindow - waitAndConsume(RemoteWindow[client](ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922])) - requested=6, available=2097152
[main] DEBUG org.apache.sshd.common.channel.RemoteWindow - Consume RemoteWindow[client](ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) by 6 down to 2097146
[main] TRACE org.apache.sshd.client.channel.ChannelShell - flush(ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) send SSH_MSG_CHANNEL_DATA len=6
[main] DEBUG org.apache.sshd.client.session.ClientSessionImpl - encode(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) packet #8 sending command=94[SSH_MSG_CHANNEL_DATA] len=15
[main] TRACE org.apache.sshd.client.session.ClientSessionImpl - encode(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) packet #8 [chunk #1](15/15) 5e 00 00 00 00 00 00 00 06 73 68 65 6c 6c 0a ^........shell.
[main] TRACE org.apache.sshd.client.session.ClientSessionImpl - encode(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) packet #8 command=94[SSH_MSG_CHANNEL_DATA] len=24, pad=8, mac=null
[main] DEBUG org.apache.sshd.common.io.nio2.Nio2Session - writeBuffer(Nio2Session[local=/127.0.0.1:50588, remote=localhost/127.0.0.1:18922]) writing 44 bytes
[sshd-SshClient[2dc9b0f5]-nio2-thread-5] TRACE org.apache.sshd.common.io.nio2.Nio2Session - handleCompletedWriteCycle(Nio2Session[local=/127.0.0.1:50588, remote=localhost/127.0.0.1:18922]) finished writing len=44 at cycle=13 after 405205 nanos
-> shell
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] TRACE org.apache.sshd.common.io.nio2.Nio2Session - handleReadCycleCompletion(Nio2Session[local=/127.0.0.1:50588, remote=localhost/127.0.0.1:18922]) read 88 bytes after 47811615 nanos at cycle=14
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] TRACE org.apache.sshd.client.session.ClientSessionImpl - decode(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) packet #13 [chunk #1](12/12) 5e 00 00 00 00 00 00 00 03 73 68 65 ^........she
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] DEBUG org.apache.sshd.client.session.ClientSessionImpl - doHandleMessage(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) process #12 SSH_MSG_CHANNEL_DATA
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] DEBUG org.apache.sshd.common.channel.LocalWindow - Consume LocalWindow[client](ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) by 3 down to 2096731
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] DEBUG org.apache.sshd.client.channel.ChannelShell - handleData(ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) SSH_MSG_CHANNEL_DATA len=3
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] TRACE org.apache.sshd.client.channel.ChannelShell - handleData(ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) [chunk #1](3/3) 73 68 65 she
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] TRACE org.apache.sshd.client.session.ClientSessionImpl - decode(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) packet #14 [chunk #1](14/14) 5e 00 00 00 00 00 00 00 05 6c 6c 0d 0d 0a ^........ll...
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] DEBUG org.apache.sshd.client.session.ClientSessionImpl - doHandleMessage(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) process #13 SSH_MSG_CHANNEL_DATA
<- she
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] DEBUG org.apache.sshd.common.channel.LocalWindow - Consume LocalWindow[client](ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) by 5 down to 2096726
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] DEBUG org.apache.sshd.client.channel.ChannelShell - handleData(ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) SSH_MSG_CHANNEL_DATA len=5
[sshd-SshClient[2dc9b0f5]-nio2-thread-6] TRACE org.apache.sshd.client.channel.ChannelShell - handleData(ChannelShell[id=0, recipient=0]-ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) [chunk #1](5/5) 6c 6c 0d 0d 0a ll...
<- ll
[sshd-SshClient[2dc9b0f5]-nio2-thread-1] TRACE org.apache.sshd.common.io.nio2.Nio2Session - handleReadCycleCompletion(Nio2Session[local=/127.0.0.1:50588, remote=localhost/127.0.0.1:18922]) read 180 bytes after 83004351 nanos at cycle=15
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "towsb1 (via GitHub)" <gi...@apache.org>.
towsb1 commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4255117638
I found this line in the logs, which I believe shows that its using SSH v2.
`[sshd-SshClient[2dc9b0f5]-nio2-thread-3] DEBUG org.apache.sshd.client.session.ClientSessionImpl - readIdentification(ClientSessionImpl[osg-si@localhost/127.0.0.1:18922]) Server version string: SSH-2.0-OpenSSH_8.5`
Being that this shows that the problem definitely isn't with MINA SSHD, I'll close this ticket and investigate further on my end. Thank you for your assistance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "tomaswolf (via GitHub)" <gi...@apache.org>.
tomaswolf commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4172221597
Try 2.17.1. I think this was fixed by commit 5ee81f47.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "tomaswolf (via GitHub)" <gi...@apache.org>.
tomaswolf commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4250251913
What's this server's identification string (sent at the very beginning of an SSH connection)? Is it SSH v2 or v1? Note that Apache MINA SSHD does _not_ do SSH v1. Among other things the way terminal modes are requested is different.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "towsb1 (via GitHub)" <gi...@apache.org>.
towsb1 closed issue #893: All output echoed back on input on a ChannelShell
URL: https://github.com/apache/mina-sshd/issues/893
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "towsb1 (via GitHub)" <gi...@apache.org>.
towsb1 commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4199969849
Yeah, the only SSH servers I have at my disposal to test against are proprietary and behind firewalls, I can't provide access to them. That said, if you change what text its waiting for to match the prompt on any other server, you should see the first command it writes echoed back (in my output you can see "`-> shell`" followed by "`<- shell`").
I just checked our old JSch code, and while I thought it redirected the error out to standard out, it looks like it doesn't. That said, I did retry this with that setRedirectErrorStream() line commented out and got the same results.
I'll see if I can put together something similar for the JSch implementation, just for comparison. We were using an extremely old version (0.1.49, from 2012) before rewriting everything for mina.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "towsb1 (via GitHub)" <gi...@apache.org>.
towsb1 commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4173407003
My apologies, I didn't specify the package properly. I'm working with the org.apache.sshd.client package, #469 deals with the sshd.server package. Upgrading to 2.17.1 still shows the same problem with everything written with `ChannelShell.getInvertedIn().write()` being echoed back in what's returned from `ChannelShell.getInvertedOut().read()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "tomaswolf (via GitHub)" <gi...@apache.org>.
tomaswolf commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4178589125
Also please tell on which platform your client is running.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "towsb1 (via GitHub)" <gi...@apache.org>.
towsb1 commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4195086602
I'm working on Java 17 (OpenJDK 17.0.18+8-LTS). I've drawn up some code that roughly boils down what my implementation does in the codebase I'm working on, and it shows the output echo. Connecting to this exact same server with an old jsch implementation doesn't produce this echo, so I know its not the server that's doing it.
[output.txt](https://github.com/user-attachments/files/26520972/output.txt)
[SSHEchoExample.java](https://github.com/user-attachments/files/26520944/SSHEchoExample.java)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "tomaswolf (via GitHub)" <gi...@apache.org>.
tomaswolf commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4200924233
Cannot reproduce. I've rewritten your client as a JUnit test, running it against OpenSSH in Alpine 3.19:
[OpenSshChannelShellTest.java](https://github.com/user-attachments/files/26544641/OpenSshChannelShellTest.java)
Running with Apache MINA SSHD 2.17.1 on Java 17 (and the docker engine up) I get the following output:
```
<- Welcome to Alpine!
The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.
You can setup the system with the command: setup-alpine
You may change
<- this message by editing /etc/motd.
<- Environment:
USER=bob
LOGNAME=bob
HOME=/home/bob
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAIL=/var/mail/bob
SHELL=/bin/ash
TERM=dummy
SSH_CLIENT=192.168.65.1 24853 22
SSH_CONNECTION=192.168.65.1 24853 1
<- 72.17.0.3 22
SSH_TTY=/dev/pts/0
<- 72a364d41225:~$
-> /bin/sh -i
<- ~ $
-> pwd
<- /home/bob
~ $
-> exit
<- 72a364d41225:~$
-> exit
```
Looks fine to me.
I suggest you run your client with debug logging and see what you actually get from the server. If debug logging doesn't help use trace logging level.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
Re: [I] All output echoed back on input on a ChannelShell [mina-sshd]
Posted by "tomaswolf (via GitHub)" <gi...@apache.org>.
tomaswolf commented on issue #893:
URL: https://github.com/apache/mina-sshd/issues/893#issuecomment-4250147333
That shows that your client sends `"shell" + LF`, and then the server sends back two messages:
1. "she"
2. "ll" + CR + CR + LF.
So the server _does_ echo, and it does so on the normal output stream, not on the error stream. Therefore the client is correctly outputting it.
I don't know why your server sends back two messages instead of one. The line ending is a bit strange, too. (I'd have expected either CR + LF or a plain LF, but not _two_ CRs and a LF).
Why does your j2ssh code does not output this, or what does the j2ssh code do differently to not get that echo?
What happens if you send not `"shell" + LF` but `"shell" + CR + LF`?
In any case, this proves that the problem is not with the Apache MINA SSHD client.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org