Tag Archives: Tips & Tricks

Linux Tips And Tricks About SSH And Sockets

Count the number of SSH commands

SSH connections from a local machine to a remote machine. The following command will give you the count:

ss | grep -vE ‘State’ | awk ‘{print $1 “–>” “Local(“$4″)” “to” “Remote(“$5″)”}’ |grep -e ssh |wc -l

And the following command will print out the SSH connections from the local machine to the remote machine.

ss | grep -vE ‘State’ | awk ‘{print $1 “–>” “Local(“$4″)” “to” “Remote(“$5″)”}’ |grep -e ssh

Investigation of sockets

To display the names of the ports that are connected to a remote server we can you this command

ss | grep -vE ‘State’ | awk ‘{print $5}’ | cut -d’:’ -f2 |sort | uniq

This command will print only the established connections port names.

Note: Please type these command do not copy and paste otherwise it will give you error because of the blog format.