L
L
l2p2014-01-07 09:59:36
MySQL
l2p, 2014-01-07 09:59:36

How to keep ssh connection alive?

Axis - Debian. I connect like this:

ssh -f -N -L 3307:сервер.mysql.ru:3306 [email protected]сервер.ru

But often the connection is simply deleted and you have to re-register.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Denis, 2014-01-07
@uscr

This is fine.
habrahabr.ru/post/81607 :
It's no secret that the connection sometimes breaks, the tunnels will fall off by timeout.
In order not to bother ourselves with the additional monotonous driving in of a command to raise the tunnel and monitoring this process, we automate it. Feel free to enter:
$ crontab -e
and create a schedule like this:
TUNCMD1='ssh -f -N -R 2222:10.11.12.13:22 [email protected]'
TUNCMD2='ssh -f -N -R 2080:10.11 .12.14:80 [email protected]'
*/5 * * * * pgrep -f "$TUNCMD1" &>/dev/null || $TUNCMD1
*/5 * * * * pgrep -f "$TUNCMD2" &>/dev/null || $TUNCMD2

T
tushev, 2014-01-07
@tushev

I solved the problem of breaking connections by timeout in SSH by setting ServerAliveInterval 60 in the
/etc/ssh/ssh_config
file on the client machine

K
KEKSOV, 2014-01-07
@KEKSOV

At work I have SSHD on the server and a working machine under Windows. Sometimes I need to go from home to work via RDP, and sometimes from work home via RDP.
First, a couple of handy aliases:

alias ssh='ssh -o TCPKeepAlive=no -o ServerAliveInterval=15 -o ServerAliveCountMax=10'
alias mars='ssh [email protected]_IP'

And the actual command for organizing an ssh channel, which I run on my home laptop in cygwin:
If you do not need port forwarding, then just do not write them. I have been successfully using this configuration for several years - there are no breaks;) I tried autossh, but something didn’t work out with it, sometimes I had to do kill -9

V
Vlad Zhivotnev, 2014-01-07
@inkvizitor68sl

autossh is here to help. The syntax is the same as ssh.
ServerAliveInterval should not be included, by the way.

S
Sergey, 2014-01-07
@bondbig

If you need a permanent and long-term connection, then I would have already done everything on openvpn.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question