Skip to content

Instantly share code, notes, and snippets.

@leosaa
Last active April 16, 2020 22:55
Show Gist options
  • Save leosaa/bdcb221be9df44a304d033d6aeca50ca to your computer and use it in GitHub Desktop.
Save leosaa/bdcb221be9df44a304d033d6aeca50ca to your computer and use it in GitHub Desktop.

Setting ssh tunnel

In order to connect to MySQL over a ssh tunnel, you have to set your ssh config as follow:

edit your config file.

Edit your .ssh/config file and add the following lines:

 Host chinoserver
     Hostname 192.168.100.200
     LocalForward 3306 127.0.0.1:3306
     User username
     Port 22

(Optional) and:

 Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa
  ControlMaster auto
  ControlPath ~/.ssh/sockets/%r@%h-%p
mkdir ~/.ssh/sockets

Then you'll be able to connect to mysql as follow:

ssh chinoserver

In other terminal or in a MySQL client:

mysql -uUser -Ppassword -h localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment