Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating shell without PTY #1418

Closed
scott-xu opened this issue May 30, 2024 · 3 comments · Fixed by #1419
Closed

Support creating shell without PTY #1418

scott-xu opened this issue May 30, 2024 · 3 comments · Fixed by #1419

Comments

@scott-xu
Copy link
Collaborator

scott-xu commented May 30, 2024

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
Copy link
Collaborator Author

scott-xu commented May 30, 2024

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

scott-xu added a commit to scott-xu/SSH.NET that referenced this issue May 30, 2024
@scott-xu scott-xu changed the title Support disabling PTY when create shell Support creating shell without PTY May 31, 2024
@scott-xu
Copy link
Collaborator Author

scott-xu commented Jun 1, 2024

Here's the same setting in Putty:

@scott-xu
Copy link
Collaborator Author

scott-xu commented Jun 7, 2024

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();
        }

sendevman pushed a commit to sendevman/SSH.NET that referenced this issue Sep 1, 2024
* Support creating Shell(Stream) without PTY
Fixes sshnet/SSH.NET#1418

* Add integration test for "PermitTTY no"

* Fix Integration Test

* Remove duplicate shell request

* Put common operations in a shared constructor. Update xml doc comments.

* Update comments and method overriding

* Update per code review

* Update integration tests

* Renaming

* Make `bufferSize` optional

* Try fix the test

* Update per code review

* try agian

* try again

* docs

* doc

---------

Co-authored-by: Rob Hague <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant