Created
April 28, 2018 15:32
-
-
Save fredericmohr/6075d9d99c53a792b48a3af0f319a49b to your computer and use it in GitHub Desktop.
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
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