我已经看过很多次Paramiko的文档了。我仍然不能找到我的问题的答案:
为什么我不能事先调用channel.invoke_shell()
而不调用channel.get_pty()
呢?-这是我从文档中得到的理解-如果我想使用channel.get_pty()
,就不需要调用channel.exec_command()
。但是,如果我想在channel.send()
或channel.recv()
中使用交互式外壳,该怎么办呢?这是强制性的吗?
这是我的尝试:
client = paramiko.SSHClient()
# Set SSH key parameters to auto accept unknown hosts
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the host
client.connect(hostname=hostname, username=username, password=password)
channel = client.get_transport().open_session()
channel.invoke_shell() # ---> Channel closed Exception here
channel.send(cmd + "\r")
有了这个,我得到了paramiko.ssh_exception.SSHException: Channel closed
。如果我在invoke_shell()
之前调用channel.get_pty()
,它会起作用。我只想使用交互式shell,而不是终端语义。有可能吗?
链接日志:
plink.exe -T -v user@host -pw password interactive-tool.exe
Looking up host "host" for SSH connection
Connecting to host port 22
We claim version: SSH-2.0-PuTTY_Release_0.72
Remote version: SSH-2.0-OpenSSH_for_Windows_7.7
Using SSH protocol version 2
No GSSAPI security context available
Doing ECDH key exchange with curve Curve25519 and hash SHA-256 (unaccelerated)
Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
Host key fingerprint is:
ssh-ed25519 255 xx:xx:xx:xx
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (unaccelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (unaccelerated) inbound MAC algorithm
Attempting keyboard-interactive authentication
Using username "user".
Server refused keyboard-interactive authentication
Sent password
Access granted
Access granted. Press Return to begin session.
Opening main session channel
Opened main channel
Started a shell/command
发布于 2019-09-25 15:08:44
可以在不调用Channel.get_pty()
的情况下调用Channel.invoke_shell()
。
如果它不工作,这是服务器的限制,而不是JSch的限制。
而且你已经know from your previous question它是这样的。
在Windows 10 Pro 1903上使用我的Win32-OpenSSH 7.7,我可以在没有TTY的情况下使用shell会话,没有任何问题:
C:\>echo ipconfig | plink -T username@localhost -pw password
Using username "username".
Microsoft Windows [Version 10.0.18362.356]
(c) 2019 Microsoft Corporation. All rights reserved.
username@COMPUTERNAME C:\Users\username>ipconfig
Windows IP Configuration
Ethernet adapter Ethernet 2:
...
https://stackoverflow.com/questions/58063024
复制相似问题