Skip to content

Instantly share code, notes, and snippets.

@pixelicous
Forked from Mins/mysql_secure.sh
Last active July 21, 2020 23:10
Show Gist options
  • Save pixelicous/6a82f5232f74e902afff1edbe2bfab52 to your computer and use it in GitHub Desktop.
Save pixelicous/6a82f5232f74e902afff1edbe2bfab52 to your computer and use it in GitHub Desktop.
Automating mysql_secure_installation
#!/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