DEV Community

Cover image for How to setup an SSH tunnel on Linux and use it to connect to remote mysql server using nodejs/php πŸ”₯
Azzouz
Azzouz

Posted on • Originally published at azaytek.com

How to setup an SSH tunnel on Linux and use it to connect to remote mysql server using nodejs/php πŸ”₯

This article is a tutorial on how to setup an ssh tunnel -and reliably ensure it's running, automatically restart it when necessary- to forward local traffic to remote destination. This works on servers running Linux and is intended to help people setup an ssh tunnel to connect to external services ie. mysql that's running on remote server. To follow along, a basic knowledge of ssh, Linux shell and cron is highly recommended.

Basics

During your programming/IT career, there is a high chance that you've already used SSH. Whether connecting to a remote server or cloning a git repository. Either way, both involving SSH on a basic level. But beyond these two uses-cases, SSH offers some others functionalities and purposes which may boost your workflow and sometimes are necessary. We are talking about SSH tunneling -aka local or remote port forwarding. In this article our main focus is the local port forwarding, especially when trying to connect from your application/script code to an external remote server; as an example, connecting nodejs script to mysql database in a remote server through ssh. Finish talking, let's get the hands dirty! Read more

Top comments (0)