SSH 详细模式:如何在没有所有“debug1”行的情况下查看传输的数据量?

SSH 详细模式:如何在没有所有“debug1”行的情况下查看传输的数据量?

在 OpenSSH 中,详细模式 ( ssh -v ...) 显示退出时的一些有用统计信息(例如Transferred: sent 3532, received 3076 bytes, in 5.5 seconds)。然而,详细模式也会打印很多debug1: ...我不关心的行。例如:

$ ssh -v -N -D localhost:12345 [email protected]
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/user/.ssh/config
debug1: /home/user/.ssh/config line 5: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
--- snip ---
debug1: channel 0: free: port listener, nchannels 4
debug1: channel 1: free: port listener, nchannels 3
debug1: channel 2: free: port listener, nchannels 2
debug1: channel 3: free: port listener, nchannels 1
Transferred: sent 3532, received 3076 bytes, in 5.5 seconds
Bytes per second: sent 638.4, received 556.0
debug1: Exit status 0

如何删除所有debug1: ...行以仅显示数据使用统计信息?我只想看Transferred: ...Bytes per second: ...线。我尝试过ssh -v ... 2>&1 | sed '/debug1/d',但这不起作用,因为Ctrlc会产生一个发送到前台进程组中所有进程的 SIGINT。sed在使用情况统计信息发送到其标准输入之前终止,因此永远不会打印使用情况统计信息。

我使用/bin/sh(不是 bash)作为我的 shell。

答案1

“已传输...”消息在“详细”日志级别打印。您可以使用以下命令将 ssh 设置为“详细”级别“-o LogLevel”选项

% ssh -o LogLevel=verbose localhost echo hello
Authenticated to localhost ([::1]:22).
hello
Transferred: sent 2768, received 2880 bytes, in 0.0 seconds
Bytes per second: sent 117942.8, received 122715.1
% 

.ssh/config如果您希望它自动发生,您可以在文件中进行设置:

Host example.com
    LogLevel verbose

相关内容