![SSH 详细模式:如何在没有所有“debug1”行的情况下查看传输的数据量?](https://linux22.com/image/199932/SSH%20%E8%AF%A6%E7%BB%86%E6%A8%A1%E5%BC%8F%EF%BC%9A%E5%A6%82%E4%BD%95%E5%9C%A8%E6%B2%A1%E6%9C%89%E6%89%80%E6%9C%89%E2%80%9Cdebug1%E2%80%9D%E8%A1%8C%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E6%9F%A5%E7%9C%8B%E4%BC%A0%E8%BE%93%E7%9A%84%E6%95%B0%E6%8D%AE%E9%87%8F%EF%BC%9F.png)
在 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