Created
October 13, 2015 20:32
-
-
Save Lewiscowles1986/973f4fa5f0a92f152cd5 to your computer and use it in GitHub Desktop.
MySQL (MariaDB) secure provision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Root Check | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
apt-get install -qq expect | |
# MariaDB | |
MYSQLPW=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c16` | |
export DEBIAN_FRONTEND=noninteractive | |
debconf-set-selections <<< "mariadb-server mysql-server/root_password password ${MYSQLPW}" | |
debconf-set-selections <<< "mariadb-server mysql-server/root_password_again password ${MYSQLPW}" | |
apt-get install -qq mariadb-server | |
echo "MariaDB Root Password: ${MYSQLPW}" >> /etc/autosetup | |
SECURE_MYSQL=$(expect -c " | |
set timeout 10 | |
spawn mysql_secure_installation | |
expect \"Enter current password for root (enter for none):\" | |
send \"${MYSQLPW}\r\" | |
expect \"Change the root password?\" | |
send \"n\r\" | |
expect \"Remove anonymous users?\" | |
send \"y\r\" | |
expect \"Disallow root login remotely?\" | |
send \"y\r\" | |
expect \"Remove test database and access to it?\" | |
send \"y\r\" | |
expect \"Reload privilege tables now?\" | |
send \"y\r\" | |
expect eof | |
") | |
echo "${SECURE_MYSQL}" | |
apt-get purge -qq expect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment