This is loosely related to one of my recent answers. I've listed 4 methods of adding a new user via mkpasswd and useradd combination on Ubuntu 16.04.
Command substitution:
sudo -p ">" useradd -m -s /bin/bash -p $(mkpasswd --hash=SHA-512 "123" ) newusrSingle quoting:
sudo -p ">" useradd -m -s /bin/sh -p 'GVhvDY$vhw89D2X0bd2REQWE' newusr2Passing via pipe to
xargs:mkpasswd -m sha-512 'password1' | sudo -p '>' xargs -I % useradd -p % newuser1Appending backslashes to each
$useradd -m -s /bin/bash -p \$6\$5AfGzrQ9u\$r6Q7Vt6h8f2rr4TuW4ZA22m6/eoQh9ciwUuMDtVBX31tR3Tb0o9EB1eBdZ2L9mvT.pX3dIEfxipMoQ0LtTR3V1 newuser
In case of method 4 and 2, it's clear that hashed password appears in the process list; this is not entirely secure. However, I'm curious about methods 3 and 1. Do command substitution and piping prevent a malicious user from somehow obtaining the hashed password ? Can malicious user somehow read stdout or stdin of either command ?