Answer the question
In order to leave comments, you need to log in
How to make ssh tunnels create and reconnect automatically?
I don't know much about linux. the task such - that from the server to be connected to databases which are located on other servers. I sort of figured out how to manually create tunnels and everything works. but as far as I understand, they work exactly until I close Putty (that is, I connect to the server via ssh too).
So here's how to make these connections run when the main server boots up and try to auto-recover in case of breaks there, let's say. I'm looking for, I read, but I don't have enough knowledge to somehow apply it. I found that there is an autossh package that seems to solve this problem, but I can’t find explanations on how to use it to solve my problem.
thanks for any help =)
Answer the question
In order to leave comments, you need to log in
autossh needs to be started along with the system, for example by pushing it into systemd .
[Unit]
Description=AutoSSH service for port 2222
After=network.target
[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -NL 2221:localhost:2222 -o TCPKeepAlive=yes [email protected]
[Install]
WantedBy=multi-user.target
flock -n /tmp/tun-lock -c "autossh -R 8080:127.0.0.1:8080 [email protected]"
In cron for once every 5 minutes, for example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question