Skip to content

Instantly share code, notes, and snippets.

@brandongalbraith
Forked from btompkins/Fabric-UserSetup.py
Last active August 29, 2015 14:16
Show Gist options
  • Save brandongalbraith/ba8f62becfe2193e6488 to your computer and use it in GitHub Desktop.
Save brandongalbraith/ba8f62becfe2193e6488 to your computer and use it in GitHub Desktop.
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