Python 如何与帕拉米科互动';什么是交互式shell会话?

Python 如何与帕拉米科互动';什么是交互式shell会话?,python,paramiko,Python,Paramiko,我有一些Paramiko代码,其中我使用invoke_shell方法请求远程服务器上的交互式ssh shell会话。方法概述如下: 以下是相关代码的摘要: sshClient = paramiko.SSHClient() sshClient.connect('127.0.0.1', username='matt', password='password') channel = sshClient.get_transport().open_session() channel.get_pty() c

我有一些Paramiko代码,其中我使用invoke_shell方法请求远程服务器上的交互式ssh shell会话。方法概述如下:

以下是相关代码的摘要:

sshClient = paramiko.SSHClient()
sshClient.connect('127.0.0.1', username='matt', password='password')
channel = sshClient.get_transport().open_session()
channel.get_pty()
channel.invoke_shell()

while True:
    command = raw_input('$ ')
    if command == 'exit':
        break

    channel.send(command + "\n")

    while True:
        if channel.recv_ready():
            output = channel.recv(1024)
            print output
        else:
            time.sleep(0.5)
            if not(channel.recv_ready()):
                break

sshClient.close()
我的问题是:有没有更好的方式与shell交互?上面的方法是有效的,但是有两个提示(matt@kali:~$和$from raw_input),如交互式shell测试运行的屏幕截图所示。我想我需要你帮我写信给标准密码?对不起,我代码不多。提前谢谢

我导入了一个在Paramiko的GitHub上找到的文件。导入后,我只需将代码更改为:

try:
    import interactive
except ImportError:
    from . import interactive

...
...

channel.invoke_shell()
interactive.interactive_shell(channel)
sshClient.close()
您可以在调用远程shell后尝试禁用echo:

channel.invoke_shell()
channel.send("stty -echo\n")

while True:
    command = raw_input() # no need for `$ ' anymore
    ... ...

谢谢@whjm。除了为了好玩而编写SSH客户机之外,没有其他用途。我宁愿和帕拉米科在一起。