Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active May 22, 2023 16:10
Show Gist options
  • Save nepsilon/e87f677510565c5acf59 to your computer and use it in GitHub Desktop.
Save nepsilon/e87f677510565c5acf59 to your computer and use it in GitHub Desktop.
How to list open SSH tunnels — First published in fullweb.io issue #34

How to list open SSH tunnels?

Very often a database in production only accept connections from localhost, and we resort to use SSH tunneling to access it remotely. While tunnels are running in the background and we connect to the database on localhost, we need to know if we’re really talking to our localhost or to the remote machine.

List all open SSH tunnels with:

sudo lsof -i -n | grep ssh

Some useful options to consider:

# -i shows the internet addresses
# -n does not resolve IP addresses
@MhmRhm
Copy link

MhmRhm commented May 22, 2023

one useful command is watch "ps aux | grep ssh | grep -Eo '^[^ ]+' | sort | uniq" to see who is online.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment