debugging 如何记录ssh调试信息?

i2loujxw  于 2023-08-06  发布在  其他
关注(0)|答案(3)|浏览(115)

我需要将ssh调试信息的输出写入文件。这

ssh -v root@172.16.248.xx > result.txt
ssh -v root@172.16.248.xx 2>&1 > result.txt

字符串
不工作,文件result.txt是空的,但在屏幕上我看到一堆调试行,如:

OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 172.16.248.xx [172.16.248.xx] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
etc


有没有办法将这些行重定向到文件?

klh5stk1

klh5stk11#

您必须在命令行上更改重定向的顺序:

ssh -v root@172.16.248.xx >result.txt 2>&1

字符串
或者只是:

ssh -v root@172.16.248.xx 2>result.txt

at0kjp5o

at0kjp5o2#

根据文档,您可以使用-E选项将调试日志存储在文件中:

-E log_file
         Append debug logs to log_file instead of standard error.

字符串

laik7k3q

laik7k3q3#

显然,将这个“隐藏的”调试输出保存到文件的最佳方法是使用logsave:

logsave result.txt ssh -v root@172.16.248.xx

字符串

相关问题