Nov 24, 2014 Tags: Howto, Linux

Howto SSH

Snippets, howtos, tips and tricks around SSH. This post will be updated as needed.

See also: Using Linux

Port Forwarding

Connect to a remote database

Readings: OpenSSH manual, Quick-Tip SSH Tunneling Made Easy

Create Tunnel

Create a tunnel to port 3306 on the remote server. This is the standard port for MySQL. Example:

ssh -N -f -L 13306:localhost:3306 \
    sshuser@remote-server.com

Options:

-N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
-f Send ssh into the background.
-L In this example: forward the local port 13306 to the remote port 3306.

Provide MySQL Access Rights

Make sure the MySQL user and the database are opened to TCP access:

UPDATE USER SET host='%' WHERE user='DBUSER';
UPDATE DB SET host='%' WHERE user='DBUSER';

Connect to Remote MySQL Service

Now you can connect to the MySQL service running on the server:

localmachine>$  mysql -h 127.0.0.1 -P 13306 -u DBUSER -pDBPASSWORD

Attention: -h localhost did not work for me. Save time and write -h 127.0.0.1 instead!

Note: This technique will only work if access for remote machines is enabled on the server:

# in file: /etc/mysql/my.cnf

## disable remote access:
#bind-address           = 127.0.0.1

# enable remote access:
bind-address            = 0.0.0.0

# Restart MySQL after changing this section - a reload is not enough:
$ service mysql restart

See MySQL server system variables

Warning: Allowing network access for MySQL creates potential security risks. Turn the feature off whenever you can!

Comments

comments powered by Disqus

Previous topic

Extend an Extbase Domain Model "On the Fly"

Next topic

Linux Scripts for Easy YouTrack Installation

Tags

Archives

Languages

Recent Posts

This Page