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.
example for connect remote elasticsearch server
ssh -C -f -N -g -L 9200:127.0.0.1:9200 user@ipaddress
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
Remove all tunnels
pgrep ssh | xargs kill