首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如果不使用Channel.invoke_shell(),是否可以在不事先调用Channel.get_pty()的情况下调用Channel.exec_command()

如果不使用Channel.invoke_shell(),是否可以在不事先调用Channel.get_pty()的情况下调用Channel.exec_command()
EN

Stack Overflow用户
提问于 2019-09-23 12:58:50
回答 1查看 969关注 0票数 1

我已经看过很多次Paramiko的文档了。我仍然不能找到我的问题的答案:

为什么我不能事先调用channel.invoke_shell()而不调用channel.get_pty()呢?-这是我从文档中得到的理解-如果我想使用channel.get_pty(),就不需要调用channel.exec_command()。但是,如果我想在channel.send()channel.recv()中使用交互式外壳,该怎么办呢?这是强制性的吗?

这是我的尝试:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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,而不是终端语义。有可能吗?

链接日志:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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
EN

回答 1

Stack Overflow用户

发布于 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会话,没有任何问题:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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:

...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58063024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文