forked from team/makeuser
17 lines
805 B
Python
Executable File
17 lines
805 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import subprocess,argparse,random,string,crypt
|
|
|
|
parser = argparse.ArgumentParser(prog="makeuser",description="A user adding script.")
|
|
parser.add_argument("username",help="Username of user.")
|
|
parser.add_argument("email",help="Email of user.")
|
|
parser.add_argument("key",help="The user's SSH pubkey.")
|
|
args = parser.parse_args()
|
|
|
|
pw = "".join(random.sample(string.ascii_letters+string.digits,20))
|
|
cr = crypt.crypt(pw)
|
|
|
|
subprocess.run("sudo useradd -m -g 100 -p {} -s /bin/bash {}".format(cr,args.username),shell=True)
|
|
subprocess.run("echo '{}' | sudo tee /home/{}/.ssh/authorized_keys".format(args.key,args.username),shell=True)
|
|
subprocess.run("sed -e 's/newusername/{}/' -e 's/newpassword/{}/' email.tmpl | sendmail {} sudoers@tilde.team".format(args.username,pw,args.email),shell=True)
|