Get status of autossh tunnel

5,974

Looks like someone gave a pretty thorough answer on Stack Exchange using a shell script.

Share:
5,974
ericksonla
Author by

ericksonla

Updated on September 18, 2022

Comments

  • ericksonla
    ericksonla over 1 year

    I created a an ssh tunnel using autossh using autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -fN -T -R 22222:localhost:22 console@<server_ip>. It worked fine for a while but now appears closed. How can I check whether the tunnel is open?

    I tried:

    lsof -i -n | egrep '\<ssh\>' | grep <server_ip>

    This returned:

    ssh 28517 username 3u IPv4 4649313 0t0 TCP 192.168.13.100:37096-><server_ip>:ssh (ESTABLISHED)

    I thought that response should indicate that the tunnel is open (I would expect return=1 if no tunnel), but when I try to use the tunnel I get:

    ssh: connect to host localhost port 22: Connection refused

    What do I need to use to check the status of the tunnel from the client?

  • ericksonla
    ericksonla over 6 years
    I had looked at that question but I thought it wasn't applicable because the OP was using -L instead of -R. In the accepted answer I missed that netstat was being run on the server, not the client. I've got it applied now.