Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredericmohr/6075d9d99c53a792b48a3af0f319a49b to your computer and use it in GitHub Desktop.
Save fredericmohr/6075d9d99c53a792b48a3af0f319a49b to your computer and use it in GitHub Desktop.
The following procedure prevents mysql passwords from showing up in your mysql or bash history.
### Create random password
// create random password with openssl
$ openssl rand -base64 32 | head -c 16
wZw0USspr+eTKFNQ
// create random password with python (more complex)
$ python -c "import string;from random import choice; print ''.join([choice(string.ascii_letters + string.digits + string.punctuation) for i in range(16)])"
lD#':_7vxZZW7Sm!
### Create mysql pw hash from password
$ python -c 'from hashlib import sha1; import getpass; print "*" + sha1(sha1(getpass.getpass("New MySQL Password:")).digest()).hexdigest()'
New MySQL Password:<password input doesn't show>
*64e48b3407dd769ba941a67fce1480f3caab35c8
### Use hash in mysql
// add user
mysql> create user 'username'@'server.lan' identified by password '*64e48b3407dd769ba941a67fce1480f3caab35c8';
// change user pw
mysql> update mysql.user set authentication_string='*64e48b3407dd769ba941a67fce1480f3caab35c8' where user="username";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment