将redis历史重定向到
/dev/null
不会存储auth命令,也会失去redis历史的好处。我不知道是否有办法选择性地忽略redis命令
AUTH mypassword
但是有一种方法可以让bash有选择地在bash历史中存储命令。
正在验证
redis-cli -a mypassword
通常将命令存储在bash history中,但是bash history有一个特性可以阻止它存储您选择的特定命令:如果
HISTCONTROL
环境变量具有值
ignorespace
,
ignoreboth
或
ignorespace:ignoredups
,bash history不会存储任何以空格开头的命令。(见
https://www.linuxjournal.com/content/using-bash-history-more-efficiently-histcontrol
)
$echo ${HISTCONTROL} # examine the value of HISTCONTROL
ignoreboth
记住这一点,您可以在使用时隐藏密码
redis-cli -a
:
a)
执行一次性身份验证,不要在bash历史记录中存储对redis cli的调用:
$ redis-cli -a mypassword #note the leading space
B)
使用环境变量在bash会话期间保持身份验证,但在历史记录中保留对redis cli的调用:
$ MYPASS=mypassword #note the leading space; won't be stored
$redis-cli -a ${MYPASS} #no leading space, but doesn't leak the password
您可以确认这与
history
命令:
$history #examine bash history
$history -d 345 #delete line 345 from your history if you made a mistake and want to erase that line