Managing Multiple MySQL Servers From One phpMyAdmin Installation (Using SSL Encryption)
|
Submitted by falko (Contact Author) (Forums) on Tue, 2012-09-18 18:21. :: Debian | Ubuntu | MySQL | Security
Managing Multiple MySQL Servers From One phpMyAdmin Installation (Using SSL Encryption)Version 1.0 This tutorial explains how you can manage multiple MySQL servers from one phpMyAdmin installation. For security reasons, communication between phpMyAdmin and any remote MySQL server is using SSL encryption (this is not necessary for a local MySQL server since communication between phpMyAdmin and MySQL is not leaving the server). phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the World Wide Web. phpMyAdmin supports a wide range of operations with MySQL. I do not issue any guarantee that this will work for you!
1 Preliminary NoteIn this tutorial I will show how to manage two MySQL servers - one local (local.example.com with the IP address 192.168.0.100 - this is the server where phpMyAdmin is installed) and one remote server (remote.example.com with the IP address 192.168.0.101) - from a phpMyAdmin instance. I'm assuming that phpMyAdmin is already installed (either manually or through your distribution's package manager) and working (i.e., you should already be able to manage the local MySQL server through phpMyAdmin) - I will not cover phpMyAdmin installation here. This tutorial is based on Debian Wheezy/Ubuntu 12.04. For other distributions, you might have to adjust some paths, but the principle is the same.
2 Enabling SSL Support On The Remote MySQL Serverremote.example.com: Log into MySQL... mysql -u root -p ... and run the following command on the MySQL shell: show variables like '%ssl%'; If the output is as follows (both have_openssl and have_ssl show DISABLED)... mysql> show variables like '%ssl%'; ... it means that MySQL was compiled with SSL support, but it's currently not enabled. To enable it, leave the MySQL shell first... quit; ... and open /etc/mysql/my.cnf: vi /etc/mysql/my.cnf Scroll down to the * Security Features section (within the [mysqld] section) and add a line with the word ssl to it:
Restart MySQL... /etc/init.d/mysql restart ... and check again if SSL is now enabled: mysql -u root -p show variables like '%ssl%'; Output should be as follows which means that SSL is now enabled: mysql> show variables like '%ssl%'; Type... quit; ... to leave the MySQL shell. Make sure that OpenSSL is installed: apt-get install openssl Now check your OpenSSL version: root@remote:~# openssl version If you - like me - have OpenSSL version 1.0.1c, the certificates generated by OpenSSL will cause errors like Sep 18 17:02:15 remote mysqld: SSL error: Unable to get private key from '/etc/mysql/newcerts/server-key.pem' (in /var/log/syslog on remote.example.com) and root@local:/etc/mysql/newcerts# mysql --ssl-ca=/etc/mysql/newcerts/ca-cert.pem --ssl-cert=/etc/mysql/newcerts/client-cert.pem --ssl-key=/etc/mysql/newcerts/client-key.pem -h remote.example.com -u root -p (on local.example.com when you try to establish an encrypted connection to remote.example.com), at least with MySQL 5.5; see:
To solve this issue, we simply build our own OpenSSL (this is not needed if your OpenSSL version is older than 1.0.1): cd /tmp Afterwards you will find your new OpenSSL binary in /usr/local/openssl-0.9.8/bin/openssl. Now we create the CA, server, and client certificates that we need for the SSL connections. I create these certificates in the directory /etc/mysql/newcerts which I have to create first: mkdir /etc/mysql/newcerts && cd /etc/mysql/newcerts Create CA certificate (I'm using /usr/local/openssl-0.9.8/bin/openssl here; if your system's OpenSSL version is older than 1.0.1, you can simply use openssl): /usr/local/openssl-0.9.8/bin/openssl genrsa 2048 > ca-key.pem /usr/local/openssl-0.9.8/bin/openssl req -new -x509 -nodes -days 1000 -key ca-key.pem > ca-cert.pem Create server certificate: /usr/local/openssl-0.9.8/bin/openssl req -newkey rsa:2048 -days 1000 -nodes -keyout server-key.pem > server-req.pem /usr/local/openssl-0.9.8/bin/openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem Create client certificate: /usr/local/openssl-0.9.8/bin/openssl req -newkey rsa:2048 -days 1000 -nodes -keyout client-key.pem > client-req.pem /usr/local/openssl-0.9.8/bin/openssl x509 -req -in client-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > client-cert.pem The output of... ls -l ... should now look as follows: root@remote:/etc/mysql/newcerts# ls -l We must now transfer ca-cert.pem, client-cert.pem, and client-key.pem to the local MySQL server (on local.example.com); before we do this, we create the directory /etc/mysql/newcerts on local.example.com: local.example.com: mkdir /etc/mysql/newcerts Back on remote.example.com, we can transfer the three files to local.example.com as follows:remote.example.com: scp /etc/mysql/newcerts/ca-cert.pem root@local.example.com:/etc/mysql/newcerts scp /etc/mysql/newcerts/client-cert.pem root@local.example.com:/etc/mysql/newcerts scp /etc/mysql/newcerts/client-key.pem root@local.example.com:/etc/mysql/newcerts Next, open /etc/mysql/my.cnf... vi /etc/mysql/my.cnf ... and modify the * Security Features section; uncomment the ssl-ca, ssl-cert, and ssl-key lines and fill in the correct values:
Restart MySQL: /etc/init.d/mysql restart Now log into MySQL again... mysql -u root -p ... and check that SSL is enabled and that the correct certificates go loaded: show variables like '%ssl%'; mysql> show variables like '%ssl%'; Don't leave the MySQL shell. We are now going to create a MySQL root user that is allowed to connect from local.example.com to remote.example.com and is required to use SSL: CREATE USER 'root'@'192.168.0.100' IDENTIFIED BY 'mysqlrootpassword'; GRANT USAGE ON *.* TO 'root'@'192.168.0.100' REQUIRE SSL; CREATE USER 'root'@'local.example.com' IDENTIFIED BY 'mysqlrootpassword'; GRANT USAGE ON *.* TO 'root'@'local.example.com' REQUIRE SSL; FLUSH PRIVILEGES; Now you can leave the MySQL shell: quit; That's it - we now have a MySQL root user that is allowed to connect from local.example.com to remote.example.com, but is required to use SSL encryption.
|




Recent comments
1 day 21 hours ago
2 days 6 hours ago
2 days 9 hours ago
2 days 10 hours ago
2 days 12 hours ago
2 days 13 hours ago
2 days 15 hours ago
2 days 16 hours ago
3 days 8 hours ago
3 days 9 hours ago