《如何防止Linux命令行下MySQL登錄密碼泄露?》要點:
本文介紹了如何防止Linux命令行下MySQL登錄密碼泄露?,希望對您有用。如果有疑問,可以聯系我們。
明知山有虎偏向虎山行的方案:
1、可以通過如下環境變量強制Linux不記錄敏感歷史命令
在命令行執行HISTCONTROL=ignorespace后,再輸入帶密碼的命令的前面加一個空格登錄,登錄命令不會被記錄到歷史記錄里.
[root@yunweipai~]# HISTCONTROL=ignorespace
#<==這里是臨時生效,要想永久生效,請放入/etc/bashrc.
[root@yunweipai~]#? mysql -uroot -p’yunweipai123′
#<==命令的開頭要多一個空格.
2、操作完敏感的命令后可以及時刪除命令行記錄
執行“history -d 歷史命令序號” 清除指定歷史記錄命令
[root@yunweipai~]# history|tail -4
#<==顯示歷史記錄.
252? mysql -uroot -p’yunweipai123′
#<==此條帶密碼,敏感,待刪除.
253?pwd
254?history
255?history|tail -4
[root@yunweipai~]# history -d 252
#<==刪除序號為252的歷史記錄.
[root@yunweipai~]# history|tail -5
252?pwd
#<==序號252對應的帶密碼登錄的命令已經消失.
253?history
254?history|tail -4
255?history -d 252
256?history|tail -5
執行“history -c”清除所有所有記錄
[root@yunweipai~]# history -c
[root@yunweipai~]# history
1?history
執行“>~/.bash_history”清除歷史記錄文件
3、給帶密碼的啟動腳本以及備份腳本等加700權限,用戶和組改為root.
chmod700 /data/3306/mysql
#<==可以采用kill信號的關閉方式數據庫,從而防止密碼泄露.
chmod700 /server/scripts/bak.sh
#<==將密碼寫入my.cnf配置文件,使得執行備份命令不需要加密碼.
4、把密碼寫入my.cnf配置文件并加700權限,用戶和組改為mysql.
[root@yunweipai~]# cp /application/mysql/my.cnf /etc/
[root@yunweipai~]# grep -A 2 client /etc/my.cnf
#<==配置文件開頭添加如下三行,無需重啟系統.
[client]
#<==客戶端模塊標簽.
user=root
#<==用戶參數及密碼.
password=yunweipai123
#<==密碼參數及密碼.
[root@yunweipai~]# mysql
#<==此時登錄數據庫就不用輸入密碼了.
Welcometo the MySQL monitor.? Commands end with; or \g.
YourMySQL connection id is 8
Serverversion: 5.6.34 Source distribution
…省略若干行…
Type’help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
知道山上有老虎,就不去的的方法:
[root@yunweipai~]# mysql -uroot -p
#<==這里標準dba命令行登陸命令,交互式輸入密碼可有效防止密碼泄露.
Enter password: