If I use a password as a command-line parameter it's public on the system using ps
.
But if I'm in a bash shell script and I do something like:
...
{ somecommand -p mypassword }
...
is this still going to show up in the process list? Or is this safe?
Command lines will always be visible (if only through /proc).
So the only real solution is: don't. You might supply it on stdin, or a dedicated fd:
./my_secured_process some parameters 3<<< "b@dP2ssword"
with a script like (simplicity first)
#!/bin/bash
cat 0<&3
(this sample would just dump a bad password to stdout)
Now all you need to be concerned with is:
<<<
means: Stream this text to stdin. 3<<<
means: stream this text to filedescriptor 3. As you can see with the demo script, you can then read fd 3
from the script. This is security by obscurity because stdin/stdout/stderr are the only standard (usual) shell pipe filedescriptors. — Nov 30, 2012 at 16:05 cat
(in the sample) on stdin... (filedescriptor 0
). But at least it doesn't show up on the commandline in ps
, top
, /proc/... — Nov 30, 2012 at 16:07 ./my_secured_process some parameters 3< <(printf '%s\n' b@dP2ssword)
— Jul 24, 2016 at 22:23