-
-
Save pixelicous/6a82f5232f74e902afff1edbe2bfab52 to your computer and use it in GitHub Desktop.
Automating mysql_secure_installation
This file contains hidden or 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 | |
apt -y install expect | |
MYSQL_ROOT_PASSWORD=1234 | |
SECURE_MYSQL=$(expect -c " | |
set timeout 10 | |
spawn mysql_secure_installation | |
expect \"Press y|Y for Yes, any other key for No:\" | |
send \"y\r\" | |
expect \"Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG\" | |
send \"2\r\" | |
expect \"New password:\" | |
send \"$ROOT_PASSWORD\r\" | |
expect \"Re-enter new password:\" | |
send \"$ROOT_PASSWORD\r\" | |
expect \"Do you wish to continue with the password provided?\" | |
send \"y\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 -y purge expect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment