cd /etc/stunnel- Create a certificate:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 \
-keyout stunnel.pem -out stunnel.pem - The
stunnel.conffile contains the following lines:cert = /etc/stunnel/stunnel.pem
setuid = nobody
setgid = nobody
pid = /tmp/stunnel.pid
debug = 7
output = stunnel.log
[mysqls]
accept = 3309
connect = 3306 stunnelis started
Client Config
- Create a certificate as above (not strictly necessary but otherwise the connection is open to a man in the middle attack)
stunnel.confcontains the following lines:
cert =/etc/stunnel/stunnel.pem
pid = /tmp/stunnel.pid
setuid = nobody
setgid = nobody
debug=7
output=stunnel.log
client = yes
[3309]
accept = 3309
connect = mysql.example.com:3309stunnelis started- The
mysqlclient is invoked with the following:mysql -h mysql.example.com -u mysqluser -p -P 3309
The hostname must be specified so thatmysqlwill not attempt to bind with a localmysqldvia a local socket.mysqluserneeds to be granted rights on the appropriate databases with the host beinglocalhost.localdomain. Something likegrant all on db.* to mysqluser@'localhost.localdomain' identified by 'SecretPw';
(this is done on a mysql client running onmysql.example.comby an administrator).