You can generate a password without a prompt by piping text into openssl
and passing a new flag. For example:
echo "password" | openssl passwd -apr1 -stdin
This will echo to stdout
. This way you can write a script or something instead of having to use the prompt to type in the password.
If you still wanted to append the output to the /etc/nginx/.htpasswd
file, then you would do the following:
echo "password" | openssl passwd -apr1 -stdin >> /etc/nginx/.htpasswd
Note passing password value using double-quotes can get ugly in case the password value contains
$
.