Skip to content

Instantly share code, notes, and snippets.

@btompkins
Created February 7, 2011 18:15
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save btompkins/814870 to your computer and use it in GitHub Desktop.
Save btompkins/814870 to your computer and use it in GitHub Desktop.
Simple fabric function to create a new user
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