使用 JSch 执行的命令的行为与 SSH 终端不同(绕过“是/"否"确认提示消息) [英] Commands executed using JSch behaves differently than in SSH terminal (bypasses confirm prompt message of "yes/"no")
问题描述
注意:我登录的是设备,不是电脑,所以我登录的是配置模式(而不是非配置模式).
Note: I log into a device, not a computer, so I login to configuration mode (instead of non configuration mode).
我在 Java 中使用 JSch 库,通过 SSH 协议登录.我是这样登录的:
I am using JSch library in Java, to login with an SSH protocol. I login like this:
channel = con.openChannel("shell");
channel.connect();
在某些情况下,当我通过 shell 发送一个需要 su
(配置模式)权限(更改配置)的命令时,此代码会绕过的提示确认消息 - 这可能会阻止其他用户改变配置.如果我使用 SSH 客户端/终端手动输入命令,则必须输入 yes 进行确认.
In some cases, when I send through the shell a command that needs su
(configuration mode) permissions (change configuration), this code bypasses the prompt confirmation message of - this may prevent other users from changing configuration. While if I enter the command manually with SSH client/terminal, I have to enter yes for confirmation.
有人知道为什么吗?
谢谢.
Does anyone have any idea why?
Thanks.
[]
当我通过 JSch 登录时,即使我没有在要执行的命令数组中插入是",我也可以执行配置命令.
When I log in through JSch I can do the configuration commands even, when the I don't insert "yes" to the array of commands to be executed.
推荐答案
默认情况下,JSch 不请求 PTY(伪终端).
By default the JSch does not request PTY (pseudo-terminal).
这可能导致某些命令的行为与交互式 SSH 终端不同.
That can cause some commands to behave differently than in an interactive SSH terminal.
您可以使用 ChannelSession.setPty
.
You can override this using the ChannelSession.setPty
.
如果以上没有帮助,请参阅类似的问题:
If the above does not help, see also similar questions:
这篇关于使用 JSch 执行的命令的行为与 SSH 终端不同(绕过“是/"否"确认提示消息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!