不低于3种方法。
明知山有虎偏向虎山行的方案:
1.1.1 可以通过如下环境变量强制Linux不记录敏感历史命令
在命令行执行HISTCONTROL=ignorespace后,再输入带密码的命令的前面加一个空格登录,登录命令不会被记录到历史记录里。
1
|
[root@oldboy~]
# HISTCONTROL=ignorespace
|
#<==这里是临时生效,要想永久生效,请放入/etc/bashrc。
1
|
[root@oldboy~]
# mysql -uroot-p'oldboy123'
|
#<==命令的开头要多一个空格。
1.1.2 操作完敏感的命令后可以及时删除命令行记录
执行“history -d 历史命令序号” 清除指定历史记录命令
1
|
[root@oldboy~]
# history|tail -4
|
#<==显示历史记录。
1
2
|
252 mysql -uroot -p
'oldboy123'
|
#<==此条带密码,敏感,待删除。
1
2
3
4
|
253
pwd
254
history
255
history
|
tail
-4
[root@oldboy~]
# history -d 252
|
#<==删除序号为252的历史记录。
1
2
|
[root@oldboy~]
# history|tail -5
252
pwd
|
#<==序号252对应的带密码登录的命令已经消失。
1
2
3
4
5
6
7
8
9
|
253
history
254
history
|
tail
-4
255
history
-d 252
256
history
|
tail
-5
执行“
history
-c”清除所有所有记录
[root@oldboy~]
# history -c
[root@oldboy~]
# history
1
history
执行“>~/.bash_history”清除历史记录文件
|
1.1.3 给带密码的启动脚本以及备份脚本等加700权限,用户和组改为root。
chmod 700/data/3306/mysql
#<==可以采用kill信号的关闭方式数据库,从而防止密码泄露。
chmod 700/server/scripts/bak.sh
#<==将密码写入my.cnf配置文件,使得执行备份命令不需要加密码。
1.1.4 把密码写入my.cnf配置文件并加700权限,用户和组改为mysql。
1
2
|
[root@oldboy~]
# cp /application/mysql/my.cnf /etc/
[root@oldboy~]
# grep -A 2 client/etc/my.cnf
|
#<==配置文件开头添加如下三行,无需重启系统。
1
|
[client]
|
#<==客户端模块标签。
1
|
user=root
|
#<==用户参数及密码。
1
|
password=oldboy123
|
#<==密码参数及密码。
1
|
[root@oldboy~]
# mysql
|
#<==此时登录数据库就不用输入密码了。
1
2
3
4
5
6
|
Welcometo the MySQL monitor. Commands endwith; or \g.
YourMySQL connection
id
is 8
Serverversion: 5.6.34 Source distribution
...省略若干行...
Type
'help;'
or
'\h'
for
help. Type
'\c'
to clearthe current input statement.
mysql>
|
知道山上有老虎,就不去的的方法:
1
|
[root@oldboy~]
# mysql-uroot -p
|
#<==这里标准dba命令行登陆命令,交互式输入密码可有效防止密码泄露。
1
|
Enter password:
|
本文转自 李导 51CTO博客,原文链接:http://blog.51cto.com/lidao/1912536