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

Pseudo-TTY allocation? #480

Open
codiophile opened this issue Nov 13, 2024 · 3 comments
Open

Pseudo-TTY allocation? #480

codiophile opened this issue Nov 13, 2024 · 3 comments

Comments

@codiophile
Copy link

For transparency, I have a service that starts long running commands over SSH, and I want it to be able to resume those SSH sessions after a restart. I thought I would be able to do it using screen/tmux, but they both complain about the lack of a terminal. I read about it, and when using the ssh command, the -t flag will force a pseudo-tty to be allocated, which enables you to run screen based programs.

Fortunately, I've found some evidence that this should be possible to do with SSH2:
mscdex/ssh2#718 (comment)
mscdex/ssh2#769 (comment)

Unfortunately, I have no idea how that translates to node-ssh. It also looks fairly complicated and involves writing directly to streams and listening to events. Considering that node-ssh is a thin wrapper, I wouldn't be surprised if it exposes the necessary APIs, but you'd probably still have to write to streams and listen to events to make it work.

I think this issue should primarily be considered a feature request for a neat API to execute commands with a pseudo-tty. I would greatly appreciate if you could correct me, if any of my assumptions are wrong. I'm assuming that at the time of writing, I'm better off using SSH2 directly for accomplishing this. I'm fairly likely to attempt to implement this with SSH2 and wrap it in promises, which could possibly be incorporated in node-ssh.

@codiophile
Copy link
Author

I seem to have figured out a way to do it. It's by no means a pretty solution, but basically, requestShell returns a stream that you can connect just like in the example here: mscdex/ssh2#718 (comment)

@codiophile
Copy link
Author

I found it:

await ssh.execCommand('screen -r', { execOptions: { pty: true } })

Would have saved me a lot of time if there was a section about it in the documentation. :)

@steelbrain
Copy link
Owner

Hi @codiophile! Thank you for posting your solution. Would you be interested in making a PR to the README to document this?

Happy New Year! 🌠

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

No branches or pull requests

2 participants