《如何防止Linux命令行下MySQL登錄密碼泄露?》要點(diǎn):
本文介紹了如何防止Linux命令行下MySQL登錄密碼泄露?,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
明知山有虎偏向虎山行的方案:
1、可以通過(guò)如下環(huán)境變量強(qiáng)制Linux不記錄敏感歷史命令
在命令行執(zhí)行HISTCONTROL=ignorespace后,再輸入帶密碼的命令的前面加一個(gè)空格登錄,登錄命令不會(huì)被記錄到歷史記錄里.
[root@yunweipai~]# HISTCONTROL=ignorespace
#<==這里是臨時(shí)生效,要想永久生效,請(qǐng)放入/etc/bashrc.
[root@yunweipai~]#? mysql -uroot -p’yunweipai123′
#<==命令的開(kāi)頭要多一個(gè)空格.
2、操作完敏感的命令后可以及時(shí)刪除命令行記錄
執(zhí)行“history -d 歷史命令序號(hào)” 清除指定歷史記錄命令
[root@yunweipai~]# history|tail -4
#<==顯示歷史記錄.
252? mysql -uroot -p’yunweipai123′
#<==此條帶密碼,敏感,待刪除.
253?pwd
254?history
255?history|tail -4
[root@yunweipai~]# history -d 252
#<==刪除序號(hào)為252的歷史記錄.
[root@yunweipai~]# history|tail -5
252?pwd
#<==序號(hào)252對(duì)應(yīng)的帶密碼登錄的命令已經(jīng)消失.
253?history
254?history|tail -4
255?history -d 252
256?history|tail -5
執(zhí)行“history -c”清除所有所有記錄
[root@yunweipai~]# history -c
[root@yunweipai~]# history
1?history
執(zhí)行“>~/.bash_history”清除歷史記錄文件
3、給帶密碼的啟動(dòng)腳本以及備份腳本等加700權(quán)限,用戶(hù)和組改為root.
chmod700 /data/3306/mysql
#<==可以采用kill信號(hào)的關(guān)閉方式數(shù)據(jù)庫(kù),從而防止密碼泄露.
chmod700 /server/scripts/bak.sh
#<==將密碼寫(xiě)入my.cnf配置文件,使得執(zhí)行備份命令不需要加密碼.
4、把密碼寫(xiě)入my.cnf配置文件并加700權(quán)限,用戶(hù)和組改為mysql.
[root@yunweipai~]# cp /application/mysql/my.cnf /etc/
[root@yunweipai~]# grep -A 2 client /etc/my.cnf
#<==配置文件開(kāi)頭添加如下三行,無(wú)需重啟系統(tǒng).
[client]
#<==客戶(hù)端模塊標(biāo)簽.
user=root
#<==用戶(hù)參數(shù)及密碼.
password=yunweipai123
#<==密碼參數(shù)及密碼.
[root@yunweipai~]# mysql
#<==此時(shí)登錄數(shù)據(jù)庫(kù)就不用輸入密碼了.
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
#<==這里標(biāo)準(zhǔn)dba命令行登陸命令,交互式輸入密碼可有效防止密碼泄露.
Enter password:
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/4321.html