List ssh tunnel connections

There are occasions when you would like to list ssh tunnel connections established to or from your server with information about the port numbers used.

Tunnels and other ssh connections to your server:

sudo lsof -i -n -P | grep -E '^sshd\>'

Tunnels and other ssh connections from your server:

sudo lsof -i -n -P | grep -E '^ssh\>'

If you are only interested in a particular user:

sudo lsof -i -n -P | grep -e 'remoteuser'

If you are only interested in IPv4 connections:

sudo lsof -i -n -P | grep -e 'IPv4' | grep -E '^sshd\>'
sudo lsof -i -n -P | grep -e 'IPv4' | grep -E '^ssh\>'

Another useful tool for inspecting network connections is netstat:

netstat -n --protocol inet | less

Leave a Reply

Your email address will not be published. Required fields are marked *