Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
nginx htpasswd add user (perl script)
# Script origin:
# Install:
# aptitude install -y curl \
# && curl -o /usr/local/bin/nginx_htpasswd \
# \
# && chmod +x /usr/local/bin/nginx_htpasswd
use strict;
chomp(my $filename=$ARGV[0]);
chomp(my $username=$ARGV[1]);
chomp(my $password=$ARGV[2]);
if (!$filename || !$username || !$password) {
print "USAGE: nginx_htpasswd <filename> <username> <password>\n";
} else {
open my $fh, ">>", $filename or die $!;
print $fh $username . ":" . crypt($password, $username) . "\n";
close $fh or die $!;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.