Linux socket-to-socket tunnel (MySQL example)

$ socat "UNIX-LISTEN:/tmp/mysqld.temp.sock,reuseaddr,fork" EXEC:"ssh username@remoteserver.com socat STDIO UNIX-CONNECT:/var/run/mysqld/mysqld.sock"

Won’t work with password login. You must add your RSA key to the server’s authorizedkeys file, or change the ssh command adding the -i option for a custom RSA key:

socat "UNIX-LISTEN:/tmp/mysqld.temp.sock,reuseaddr,fork" EXEC:"ssh username@remoteserver.com -i /home/user/rsa-keys/id_rsa socat STDIO UNIX-CONNECT:/var/run/mysqld/mysqld.sock"

/tmp/mysqld.temp.sock will be created locally by socat, don’t create it yourself. The folder it lives must be writable. Connect your MySQL client to this socket, with database and username set properly.

In case you need to forward a remote socket to a LOCAL PORT instead, check http://www.commandlinefu.com/commands/view/9436/socat-tcp-listen5500-execssh-userremotehost-socat-stdio-unix-connectvarrunmysqldmysqld.sock

commandlinefu.com

Diff your entire server config at ScriptRock.com

Read More here.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.