非交互式 ssh 登录后立即断开连接

非交互式 ssh 登录后立即断开连接

我正尝试通过 Linux 机器上的 ssh 从诺基亚路由器获取一些信息。

如果我这样做,ssh 就可以正常工作:

ssh [email protected]

我可以输入密码,登录,运行命令。

但是,当我执行以下操作时,它会立即断开我的连接:

ssh -v [email protected] 'show time'

Verbose output:
debug1: Next authentication method: password
[email protected]'s password: 
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_PAPER = en_US.UTF-8
debug1: Sending env LC_ADDRESS = en_US.UTF-8
debug1: Sending env LC_MONETARY = en_US.UTF-8
debug1: Sending env LC_NUMERIC = en_US.UTF-8
debug1: Sending env LC_TELEPHONE = en_US.UTF-8
debug1: Sending env LC_IDENTIFICATION = en_US.UTF-8
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_MEASUREMENT = en_US.UTF-8
debug1: Sending env LC_TIME = en_US.UTF-8
debug1: Sending env LC_NAME = en_US.UTF-8
debug1: Sending command: show time
debug1: channel 0: free: client-session, nchannels 1
Connection to 10.0.0.1 closed by remote host.
Transferred: sent 2088, received 1840 bytes, in 0.0 seconds
Bytes per second: sent 488193.7, received 430209.0
debug1: Exit status -1

如果我使用预期脚本进行连接、发送密码,然后发送命令,它可以正常工作。

可能出了什么问题?

答案1

感谢所有的评论。

最后我最终使用了 expect,因为我正在使用 bash 脚本来连接和提取信息。

相关内容