加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 服务器 > 安全 > 正文

如何防止Linux命令行下MySQL登录密码泄露?

发布时间:2021-01-13 08:54:45 所属栏目:安全 来源:网络整理
导读:《如何防止Linux命令行下MySQL登录密码泄露?》要点: 本文介绍了如何防止Linux命令行下MySQL登录密码泄露?,希望对您有用。如果有疑问,可以联系我们。 命令行登录防止MySQL密码泄露的几个小妙招. 明知山有虎偏向虎山行的方案: 1、可以通过如下环境变量

《如何防止Linux命令行下MySQL登录密码泄露?》要点:
本文介绍了如何防止Linux命令行下MySQL登录密码泄露?,希望对您有用。如果有疑问,可以联系我们。

命令行登录防止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:

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读