29 lines
873 B
Python
29 lines
873 B
Python
from subprocess import call
|
|
import os
|
|
import random
|
|
import string
|
|
import click
|
|
# Creates a new user
|
|
# adduser --disabled-password --gecos "" username
|
|
|
|
@click.command()
|
|
@click.option('--username', help='Specifies a username')
|
|
@click.option('--ssh_key', help='Specifies a ssh key')
|
|
|
|
def adduser(username, ssh_key):
|
|
# I used os at this part and will use subprocess at linking to nginx /var/www
|
|
print('At the end of this script, new user will be created. ')
|
|
print('Username:', username)
|
|
call(["adduser", "--disabled-password", "-gecos", '''""''', username])
|
|
with open("authorized_keys", "w") as keyfile:
|
|
keyfile.write(ssh_key)
|
|
move_ssh = "mv /root/projects/scripts/authorized_keys authorized_keys"
|
|
os.chdir("/home")
|
|
os.chdir(username)
|
|
os.chdir(".ssh")
|
|
os.system(move_ssh)
|
|
print('New user created!')
|
|
exit()
|
|
|
|
adduser()
|