Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log ssh debug info?

I need to write the output of ssh debug info into the file. This

ssh -v [email protected] > result.txt ssh -v [email protected] 2>&1 > result.txt 

doesn't work, the file result.txt is empty, but on the screen i see bunch of debug lines, like:

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 

Is there a way to redirect these lines to the file?

like image 245
lugger1 Avatar asked Sep 23 '11 19:09

lugger1


People also ask

How do I debug SSH?

To enable SSH debug, run the SSH command with the -v, -vv, or -vvv option: In this example, you can see what a successful SSH connection would look like with the complete back and forth communication between the hosts.

How do I check SSH logs?

On most modern systems, journalctl provides a convenient, standardized way to view ssh logs. On other systems, you can find the sshd log at /var/log/auth. log. For quick inspections, you can also use the lastlog command.

How do I run SSH in verbose mode?

The ssh client's -v switch allows you to run ssh in verbose mode, that prints debugging information about SSH connection progress, which is really useful for debugging connections, authentication, and any configuration problems.

How do I debug if SSH is not working?

Troubleshooting steps:Verify that the host IP address is correct. Verify the firewall rules, check the inbound rules allowed by the security group. Verify the port number allowed for ssh. Verify that the service is running properly.


2 Answers

You have to change the order of the redirections on the command line:

ssh -v [email protected] >result.txt 2>&1 

or just:

ssh -v [email protected] 2>result.txt 
like image 66
salva Avatar answered Sep 17 '22 02:09

salva


 -E log_file          Append debug logs to log_file instead of standard error. 
like image 22
Bhoodha Avatar answered Sep 21 '22 02:09

Bhoodha