sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
MIT License
3.87k stars 915 forks source link

Support creating shell without PTY #1418

Closed scott-xu closed 2 days ago

scott-xu commented 2 weeks ago

OpenSSH client supports -T option to disable pseudo-terminal allocation. Can we add this feature to SSH.NET as well? With this option, the output from remote does not contain control sequences. It is not user-friendly but program-friendly. Program at client side does not need to parse/draw the screen with control sequences to get the correct output.

There's already SshCommand feature which is similar with this. But SshCommand does not support interactions. SshCommand runs and ends.

https://www.man7.org/linux/man-pages/man1/ssh.1.html -T Disable pseudo-terminal allocation.

scott-xu commented 2 weeks ago

To support creating shell without PTY, we can add a new constructor for Shell and ShellStream which does not send PseudoTerminalRequest.

scott-xu commented 2 weeks ago

Here's the same setting in Putty:

scott-xu commented 1 week ago

SSHJ does have a dedicate allocatePTY method.

void allocatePTY(String term, int cols, int rows, int width, int height, Map<PTYMode, Integer> modes)
            throws ConnectionException, TransportException;

example:

        try {
            ssh.addHostKeyVerifier(new PromiscuousVerifier());
            // Set interval to enable keep-alive before connecting
            ssh.getConnection().getKeepAlive().setKeepAliveInterval(5);
            ssh.connect(args[0]);
            ssh.authPassword(args[1], args[2]);
            Session session = ssh.startSession();
            session.allocateDefaultPTY();
            new CountDownLatch(1).await();
            try {
                session.allocateDefaultPTY();
            } finally {
                session.close();
            }
        } finally {
            ssh.disconnect();
        }