Skip to content

SSH Tunnels

To use a local MySQL manager or other application to connect to a database on Stratus, an SSH tunnel is preferred.  SSH tunnels are possible with a variety of clients. Putty and OpenSSH are used in the following examples.

Before you can connect, you need several pieces of information:

  • A working SSH login to your Stratus instance.
  • The IP address that will connect to the Stratus MySQL (i.e., the same IP allowed for SSH access)
  • Your database credentials. In your Stratus management panel, expand the MySQL section and click Info to see your database username and password

If you have the above, you can proceed.

Creating a Tunnel with PuTTY

  1. Open PuTTy on your computer.

putty-92

  1. Enter the SSH Host address shown SSH > Info.

ssh info-2

  1. From the left-hand tree in PuTTY, go to Connection > SSH > Tunnels.
    • Source PortEnter "3306". If MySQL is locally using this port, enter another port number (e.g. "3307").
    • DestinationEnter the Stratus hostname combined with the host port of "3306" (e.g. "ssh.5uiwe1x3ngdgg75c.mojostratus.io:3306")
    • Click Add.

putty tunnel-42

  1. Click Open. Accept the SSH if requested.
  2. Log in with the Stratus SSH User credentials.

The SSH tunnel to the remote database is now open. Connect locally using a MySQL client application. Use an IP of 127.0.0.1 and port number of 3306.

Creating a Tunnel with OpenSSH

A secure tunnel to the Stratus database can be created using one command line:

ssh -p <SSHport> -L <localport>:mysql:3306 <SSHuser>@<SSHhost>
  • SSHport — Use the SSH Port found in your SSH Info panel.
  • localport — Normally "3306", the local port used to access MySQL. If an instance of MySQL is already running locally, an alternative port may be used, such as "3307".
  • SSHuser — Stratus SSH Username.
  • SSHhost — Found in the Stratus SSH Info panel.

Using this format, a typical OpenSSH tunnel might be created using:

ssh -p 21937 -L 3306:mysql:3306 developer_joe@ssh.5uiwe1x3ngdgg75c.mojostratus.io

After entering this into the terminal window, enter the Stratus SSH user password.

putty tunnel-42

While this tunnel connection is open, open a new terminal window and connect to the Stratus MySQL database as if it were local.

SSH tunnels between Stratus instances

SSH tunnels have become common between Stratus instances for the purpose of Magento1->Magento2 data migrations. A tunnel between instances is very similar to creating a tunnel with OpenSSH, except for the following:

  • Instead of SSH hostname, you must use the external IP address of the SSH host instead. For example, in the example above, for ssh.5uiwe1x3ngdgg75c.mojostratus.io, you would use the IP 3.231.50.120 instead.

putty tunnel-42

You can obtain the outgoing/SSH IP of the instance you are on via ssh with the command curl http://ipcheck.com/

Below is a full example of the steps needed to create an SSH tunnel between 2 instances (M1 and M2)

  • Create a new SSH user on the M1 instance, allow the public SSH key & white-list the IP from the M2 instance. (curl http://ipcheck.com/)

  • Create a screen on the M2 instance: screen -S tunnel

  • Run the following in the screen to open the tunnel to the M1 instance:

ssh -p <PORT> -L 3307:mysql:3306 <USER>@<IP OF M1>

Example:

ssh -p 22000 -L 3307:mysql:3306 transfer@34.236.255.11
  • Hit Ctrl-A-D on PC to disconnect from the screen without exiting the tunnel

You can now access both databases on the M2 instance:

Example:

Local m2 database: mysql -u user_abcdefghijk -p db_abcdefghijk
Remote m1 database: mysql -u user_zyxwvutsrq -p -P 3307 db_zyxwvutsrq

If the M2 instance is rebooted, you will need to recreate the tunnel starting at step 2 above.