Filtering SSH Packets with Tcpdump

Updated: Feb 11

Tcpdump is a command-line packet analysis tool. We can use tcpdump to capture ssh traffic to troubleshoot connection issues and look for potential security issues on a network.




What is SSH?

SSH is a protocol purpose-built for secure remote login and communicating or transmitting other secure network services over an insecure network.


The benefit of SSH is we can connect to a server from anywhere and control the majority of its functions without having to be in front of the machine.


What is the default port number for ssh?

The default port number for ssh protocol is 22 on Linux. This can be changed in the ssh configuration file /etc/ssh/sshd_config. Many hosting companies change this number to another port for security issue.


We can log in to the remote server using ssh command ssh howtouselinux.com.


How to capture SSH Traffic with Tcpdump?

We can filter tcp port 22 in tcpdump command to capture all the ssh traffic.

tcpdump -i eth0 tcp port 22
tcpdump -i eth0 'tcp[2:2] = 22'

The output of tcpdump is format dependant. A typical output line for TCP looks like this.

21:38:44.202888 IP 10.79.97.62.60915 > 216.58.220.206.22: Flags [S], seq 1580803359, win 65535, options [mss 1366,nop,wscale 6,nop,nop,TS val 552701199 ecr 0,sackOK,eol], length 0

We can save the captured packets into a file rather than printing them out by using the “-w” flag.

tcpdump -i eth0  -w /tmp/ssh.pcap tcp port 22

Related Post:

20 Advanced Tcpdump Examples On Linux

10 Useful tcpdump command examples


326 views

Join our newsletter. Get a free Linux account on Cloud.

Get a Free Cloud Server! 

We can use this cloud server to practice Linux commands. Never miss a post!

Thanks for submitting!