![]() ServerAliveCountMax - the number of "server alive" messages which may be sent without reply from the server.ServerAliveInterval - the number of seconds that the client will wait before sending a "server alive" message to the server to keep the connection alive.-i /path/to/key - Specify the path to ssh key used to establish the ssh session, without this you will have to enter username (if not supplied) and password to establish the ssh session.In this case, it means forward port 80 of the remote server to port 8080 of the client. -R 8080:localhost:80 - Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.-N - Do not execute a remote command this is useful for just forwarding ports.To create an SSH Tunnel, I issue the following command (from the NAS): ssh -NT -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -i /var/services/homes/foouser/.ssh/id_rsa -R 8080:localhost:80 -R 4443:localhost:443 explain this command: This can easily be overcome by having the client (in my case, the VPS) "ping" the server (in my case, the NAS) using the keep alive option. However, I suffered from the SSH tunnel being "closed" due to inactivity (depsite the ssh process staying up). So to reach my NAS from the internet, I simply need to create an SSH tunnel between my NAS and my VPS, that reliably stays open all the time (for round the clock access). Therefore, to reach my NAS, I have a VPS (which I rent from OVH for a very small monthly cost), and that has a fixed public IP address. I have a NAS that I want to reach from the internet, I can't use port forwarding because my ISP uses CGNAT (my public IP is not really my public IP, I'm behind another router I don't have any control over). Upstart script on Ubuntu, where /etc/inittab is not available: start on net-device-up IFACE=eth0Įxec ssh -i /path/to/rsaKey -N -o "ServerAliveInterval 180" -R 55002:localhost:22 scriptįor those who don't want to (or) can't use AutoSSH. etc/inittab, to have access to a box shipped and installed in another country, behind NAT, without port forwarding to the box, you can configure it to create an ssh tunnel back to you: tun1:2345:respawn:/usr/bin/ssh -i /path/to/rsaKey -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 'sleep 365d' sleep 5 done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes Always use ServerAliveInterval SSH option in case the tunnel issues are generated by expired NAT sessions.Īlways use a respawning method in case the connectivity goes down entirely, you have at least three options here:
0 Comments
Leave a Reply. |