Skip to content

crypt(1) for the command line

Looks like there is no passwd-compatible crypt(1) for the command line. htpasswd, unfortunately, uses a different algorithm.

This short perl script might be a replacement:


#!/usr/bin/perl -w

use strict;

while(<>) {
    my $seed = `apg -a 1 -m 8`;
    chomp;
    print crypt(&#8220;$_&#8221;, &#8220;\\$1\\$$seed&#8221;). &#8220;\\n&#8221;;
}

Or do we have something better already in the distribution?


Update: looks like mkpasswd (from the whois package, whatever makes it belong in there) does the job quite nicely, but the script shown above takes care of automatic salt creation as well. Any ideas how to do that more elegantly, without requireing apg?