bash – 从交互式命令到更少的管道输出
发布时间:2020-12-16 01:18:21 所属栏目:安全 来源:网络整理
导读:我想做点什么 openssl enc -d -aes256 -in somefile | less openssl需要来自stdin的密码.当涉及的较少时,这会搞砸. 有没有办法从交互式命令(如openssl要求输入密码)获取输出并将输出管道输入更少? 或者使用bash脚本有更好的技术吗? 也许让shell脚本请求密
我想做点什么
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |