Created
February 7, 2011 18:15
-
-
Save btompkins/814870 to your computer and use it in GitHub Desktop.
Simple fabric function to create a new user
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
def new_user(admin_username, admin_password): | |
env.user = 'root' | |
# Create the admin group and add it to the sudoers file | |
admin_group = 'admin' | |
runcmd('addgroup {group}'.format(group=admin_group)) | |
runcmd('echo "%{group} ALL=(ALL) ALL" >> /etc/sudoers'.format( | |
group=admin_group)) | |
# Create the new admin user (default group=username); add to admin group | |
runcmd('adduser {username} --disabled-password --gecos ""'.format( | |
username=admin_username)) | |
runcmd('adduser {username} {group}'.format( | |
username=admin_username, | |
group=admin_group)) | |
# Set the password for the new admin user | |
runcmd('echo "{username}:{password}" | chpasswd'.format( | |
username=admin_username, | |
password=admin_password)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment