Trouvé sur Stackoverflow.
You can do this cleanly with an ssh 'control socket'. To talk to an already-running SSH process and get it's pid, kill it etc. Use the 'control socket' (-M for master and -S for socket) as follows:
$ ssh -M -S my-ctrl-socket -fnNT -L 50000:localhost:3306 jm@sampledomain.com
$ ssh -S my-ctrl-socket -O check jm@sampledomain.com
Master running (pid=3517)
$ ssh -S my-ctrl-socket -O exit jm@sampledomain.com
Exit request sent.
Note that my-ctrl-socket will be an actual file that is created.
Ou plus simplement, comme suggéré par lminoza dans les commentaires :
mkdir ~/.ssh/tmp
Remplir dans son ~/.ssh/config
:
Host *
ControlMaster auto
ControlPath ~/.ssh/tmp/%C
Cela évite de devoir préciser la socket à chaque fois.
$ ssh -fnNT -L 50000:localhost:3306 jm@sampledomain.com
$ ssh -O check jm@sampledomain.com
Master running (pid=3517)
$ ssh -O exit jm@sampledomain.com
Exit request sent.