pythonsshterminalparamikoansi-escape

How do I start a shell without terminal emulation in Python Paramiko?


Is there a way to start a shell without terminal emulation in Python Paramiko?


Solution

  • Paramiko SSHClient.invoke_shell opens "shell" SSH channel. What is basically only a shorthand for executing user's default shell. Otherwise it does not differ to what SSH "exec" channel (used by SSHClient.exec_command) does.

    Both "shell" and "exec" SSH channels can be started with or without the terminal emulation. It's only that Paramiko SSHClient.invoke_shell method does not offer that option (while SSHClient.exec_command does – via its get_pty parameter).

    There are two alternatives:


    Though note that there's a reason, why SSHClient.invoke_shell always uses the terminal emulation. The only purpose of SSH "shell" channel is implementing an interactive SSH terminal client (like PuTTY). A terminal client without the terminal emulation makes no sense.

    That you want to use "shell" channel without the terminal emulation indicates, that you are abusing it for purposes for which it was not designed. Think twice, if there's not a better solution to what you are trying to do!