Last active
August 29, 2015 13:58
-
-
Save jbohren/10096074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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