[技巧]如何防止Linux命令行下MySQL登录密码泄露?
2017-03-17 08:47
381 查看
命令行登录防止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:
相关文章推荐
- 如何防止Linux命令行下MySQL登录密码泄露? 【转】
- 老男孩教育每日一题:2017年3月13日-如何防止Linux命令行或脚本里MySQL登录密码泄露?
- linux如何设置无密码登录mysql(如何设置无密码登陆mysql)
- 命令行登录防止MySQL密码泄露的几个小妙招。
- ssh免密码登录, 发送命令到多个Linux
- 在linux下如何通过expect正确执行自动切换登录,并且执行命令和脚本
- MySQL如何防止delete命令删除数据
- Linux下SSH跳转无密码登录或执行命令
- wamp设置内网访问和mysql如何设置登录密码
- linux下如何修改Mysql的root密码
- Linux有问必答:如何强制在下次登录Linux时更换密码
- 定制微型linux实现启用虚拟终端基于帐号密码登录、提供ssh服务,提供Web服务(下)附有命令移植脚本 推荐
- linux下mysql登录忘记密码
- 简化mysql –uroot –p登录 linux忘记mysql密码处理方法 解决root没有权限
- Linux命令之远程登录/无密码登录-ssh,ssh-keygen,ssh-copy-id
- [小白技巧]如何在Linux上检查MySQL数据表的存储引擎类型
- linux中mysql安装后,登录提示密码错误,解决办法
- 分享一下Linux系统下如何设置OpenSSH无密码登录
- Linux系统下如何做到SSH免密码登录
- 【Linux学习笔记】Linux主机如何实现无需输入密码的远程登录或脚本远程执行