Tuesday 28 July 2015

MySQL mask password

Server version: 5.6.20-enterprise



-->We can make use of 'mysql_config_editor' utility to mask password


[root@host etc]# cat my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[root@host ~]# mysql_config_editor print --all   <<First time it does not return the output>>

root@host ~]# mysql_config_editor set --user=root --password
Enter password:    <<enter password>>

[root@host ~]# mysql_config_editor print --all
   --This  prints the id and password. However they are masked.
[client]
user = root
password = *****

[root@host ~]# mysql   <<<we can login without ID & Password>>>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

14:38 (none)> exit
Bye

'mysql_config_editor' creates a file called '.mylogin.cnf' under user home directory. However we cannot see the content of this file.
mysql makes use of this file to read id & password

[root@host ~]# cat ~/.mylogin.cnf
▒5▒ןB▒▒MO▒7▒MJ▒▒▒)▒▒v"@ba▒ _m]u1!▒}▒t▒_U▒▒[`,▒▒▒▒▒"_t▒[root@host ~]# PuTTY
-bash: PuTTY: command not found


This is how we can mask the password.

----*********Play around with mysql_config_editor****---------

--Remove the file
[root@host mysql]# mysql_config_editor remove
WARNING : No login path specified, so options from the default login path will be removed.
Continue? (Press y|Y for Yes, any other key for No) : Y


[root@host mysql]# mysql_config_editor print --all
<<no output>>

[root@host mysql]# mysql_config_editor set --login-path=admin --user=root --password
Enter password:
[root@host mysql]# mysql_config_editor print --all
[admin]       <<<login-path name>>
user = root
password = *****
[root@host mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@host mysql]# mysql --login-path=admin
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.20-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

12:50 (none)> exit
Bye

[root@host mysql]# mysql_config_editor set --login-path=admin1 --user=root --password
Enter password:

[root@host mysql]# mysql_config_editor print --all
[admin]
user = root
password = *****
[admin1]       <<new loginpath>>
user = root
password = *****
[root@host mysql]# mysql_config_editor remove  --login-path=admin1

[root@host mysql]# mysql_config_editor print --all
[admin]
user = root
password = *****

<<admin1 loginpath is removed

No comments:

Post a Comment