I have a password stored in an environment variable.
read -s passwd
export passwd
Bad: Using echo $passwd
Now I want to pipe it to a command accepting the password through stdin (e.g., kinit). However, if bash has set -x enabled, then this will leak the password.
(warning: will leak password if set -x is enabled)
$ echo $passwd | kinit [email protected]
+ kinit [email protected]
+ echo secretpassword
...(kinit output)...
Alternative: Using printenv passwd
So I used printenv to write the password to stdin, instead of echo.
(is this ok?)
$ printenv passwd | kinit [email protected]
+ kinit [email protected]
+ printenv passwd
...(kinit output)...
This doesn't print the password to the bash output when I tried it.
Question: Is it OK to use printenv?
But is this actually secure? Is there a configuration of bash that could leak the password somewhere?
Edit: don't think set -x prints to stdout/stderr, fixed.
echo $passwdor runenvset -xthat make it bad to run a command withprintenv passwd