我想做点什么
- openssl enc -d -aes256 -in somefile | less
openssl需要来自stdin的密码.当涉及的较少时,这会搞砸.
有没有办法从交互式命令(如openssl要求输入密码)获取输出并将输出管道输入更少?
或者使用bash脚本有更好的技术吗?
也许让shell脚本请求密钥,然后将密钥存储在临时文件中并使用openssl的-kfile选项来查找它.希望你的openssl版本支持-kfile.
我担心这会带来安全感,但有点小心,安全漏洞可能比你想象的要小. (但你相信你的系统管理员和sudoers ……?)
- #!/bin/bash
- INFILE=somefile
- read -s -p "Enter key for $INFILE: " key
- echo
- # write the key to a temp file; use mktemp(1)
- # for safer creation of a privately-owned file.
- #
- TMPKEY=$(mktemp -t) || exit 1
- echo "$key" > "$TMPKEY"
- # will remove the temp file on script exit
- trap 'rm -f "$TMPKEY"' EXIT
- # remove the key file a couple seconds after openssl runs
- (sleep 2; rm -f "$TMPKEY") &
- openssl enc -d -aes256 -in "$INFILE" -kfile "$TMPKEY" | less
- [ -f "$TMPKEY" ] && rm -f "$TMPKEY"
- trap - EXIT
- # rest of script...
- exit 0