I would like to be able securely type text in terminal and pipe it to another command to:
- Not be recorded in terminal history
- Be hidden as you type it
- Not be recorded in any file or environmental variable
- Be in memory for shortest possible time
Ideally:
- Using commonly installed tools on linux
- Easy to use as
echo
- Not having to create any scripts/files
- Can be piped to other commands
Example of non secure input
echo "secret" | wc -c
Almost what I want:
read -s | wc -c
Basically the same way how you input password to sudo
and similar.
My use case
echo "secret" | gpg --encrypt --armor -r 1234567890ABCDEF | xclip
I am looking for a way with restrictions I mentioned in points above. Knowing that what I am looking for doesn't exist is also an answer I will accept and mark.
I created alias from accepted answer
alias secnote="{ read -s; printf %s $REPLY; } | gpg --encrypt --armor -r 123467890ABCDEF | pbcopy"
CodePudding user response:
Is this what you wanted to achieve ?
$ read -s # I type `secret`
$ echo $REPLY
secret
$ printf %s $REPLY | wc -c
6
$ unset REPLY
$ echo $REPLY
# empty now
Or you want one-liner like this :
{ read -s -p "Input a secret: "; printf %s $REPLY; } | wc -c
If you define an alias :
alias readp='{ read -s -p "Input a secret: "; printf %s $REPLY; }'
then you can do readp | wc -c