使用JSch执行的命令与SSH终端中的行为不同(绕过确认提示消息“是/”否“) [英] Commands executed using JSch behaves differently than in SSH terminal (bypasses confirm prompt message of "yes/"no")

查看:754
本文介绍了使用JSch执行的命令与SSH终端中的行为不同(绕过确认提示消息“是/”否“)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我登录的是设备,而不是计算机,因此我登录配置模式(而非非配置模式)。

Note: I log into a device, not a computer, so I login to configuration mode (instead of non configuration mode).

我正在使用JSch库Java,使用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:

  • Certain Unix commands fail with "... not found", when executed through Java using JSch
  • Certain Unix commands fail with "... not found", when executed through Java using JSch even with setPty enabled

这篇关于使用JSch执行的命令与SSH终端中的行为不同(绕过确认提示消息“是/”否“)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆