Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nginx htpasswd add user (perl script)
#!/usr/bin/perl
# Script origin: http://wiki.nginx.org/Faq#How_do_I_generate_an_.htpasswd_file_without_having_Apache_tools_installed.3F
# Install:
# aptitude install -y curl \
# && curl -o /usr/local/bin/nginx_htpasswd \
# https://gist.githubusercontent.com/2called-chaos/286965e2a4b5c1aaf056/raw/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.