Ruby SSH禁用分页

Bul*_*lki 11 ruby ssh net-ssh

有没有办法禁用或设置ruby Net-SSH连接的页面长度,所以我们不必更改远程设备上的设置?

在Cisco路由器中,我们将使用参数"终端长度0"来完成此操作,但在其他服务器上,我们不能使用任何类似的命令.可以通过Net-SSH lib设置吗?

小智 1

假设远程端有 shell,则终端高度在 LINES 环境变量中设置。你可以尝试这样设置:

Net::SSH.start('hostname', 'user') do |ssh|
  ssh.exec!('LINES=50 your-command-here')
end
Run Code Online (Sandbox Code Playgroud)

如果您没有 shell,您可以尝试使用 net-ssh 推送它:

ENV['LINES'] = '50'
Net::SSH.start('hostname', 'user', send_env: ['LINES']) do |ssh|
  ssh.exec!('your-command-here')
end
Run Code Online (Sandbox Code Playgroud)

不过这需要sshd的配合。如果是 OpenSSH,请编辑 /etc/ssh/sshd_config 并确保 AcceptEnv 包含 LINES。