Skip to content

Instantly share code, notes, and snippets.

@jbohren
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbohren/10096074 to your computer and use it in GitHub Desktop.
Save jbohren/10096074 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Term::ANSIColor;
if(@ARGV < 1) {
print " \n";
print "usage: $0 USERNAMES [--admin]\n";
print " \n";
print " This program will create a user using 'adduser' for each username\n";
print " listed in the USERNAMES file (separated by line breaks). Their\n";
print " passwords will be the same as their usernames.\n";
print " \n";
print " Options:\n";
print " \n";
print " USERNAMES: a list of usernames\n";
print " --admin: make the users administrators (sudo privileges)\n";
print " \n";
exit;
}
my $admin = 0;
if(@ARGV == 2 and $ARGV[2] == '--admin') {
$admin = 1;
}
my $filename = $ARGV[0];
open my $usernames, $filename or die "Could not open file \"$filename\": $!";
while(my $username = <$usernames>) {
chomp $username;
print colored ['yellow'], "[info] Creating user $username...\n";
`adduser --disabled-password --gecos "" $username`;
`echo "$username:$username" | chpasswd`;
if($admin) {
print colored ['red'], "[warning] Promoting $username to admin!\n";
`usermod -aG sudo $username`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment