Skip to content

Instantly share code, notes, and snippets.

@kokoye2007
Forked from Mins/mysql_secure.sh
Created January 19, 2019 14:04
Show Gist options
  • Save kokoye2007/ed30fe0605364e3dd8bf47865ba9d81a to your computer and use it in GitHub Desktop.
Save kokoye2007/ed30fe0605364e3dd8bf47865ba9d81a to your computer and use it in GitHub Desktop.
Automating mysql_secure_installation
#!/bin/bash
aptitude -y install expect
// Not required in actual script
MYSQL_ROOT_PASSWORD=abcd1234
SECURE_MYSQL=$(expect -c "
set timeout 10
spawn mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"$MYSQL\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"
aptitude -y purge expect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment