Shami's Blog

Sysadmin, Because Even Developers Need Heroes

Perl One-liner To Generate htpasswd Passwords

2014-12-29 by Mohammad H. Al-Shami

Update: An easier way to do it that doesn’t require you to install anything special (Works with nginx)

openssl passwd -apr1

Instead of having to install Apache or use an untrusted website just to generate the required password, you can use the following perl one liner

perl -e 'chomp($password=<>);chomp($salt=`tr -dc A-Za-z0-9 </dev/urandom | head -c 1024`); print crypt($password,$salt)."\n";'