Ssh – why use ssh tunneling for thesql server

lampMySQLssh

i've got ubuntu server acting as my lamp server for my php websites.

mysql server is installed and opened for the localhost port.

i have read about how to tunnel through ssh to my mysql server.

but i havent understood why this is better than opening the mysql server directly for the internet port.

cause in either way, a hacker could brute force the port for passwords. either mysql port (3306) if opened for the public or ssh (22) if using tunneling.

so why is it better to use ssh tunneling for mysql (and many other server applications)?

Best Answer

If you use SSH tunneling, then your SSH and MySQL passwords are both encrypted during communication -- as well as all data that passes through the tunnel. If you're not using an SSH tunnel and you're not using MySQL's SSL support, there is no encrypting and a malicious third party could use packet sniffing or other nefarious means to eavesdrop on your communications.

Also, if you're using SSH tunneling, then you will be alerted if the remote machine's SSH key changes. This will not happen with standard MySQL, meaning an attacker could use IP spoofing or a Man in the Middle attack to disrupt/interfere/eavesdrop on your communications.

For more information, see: