Skip to content

Instantly share code, notes, and snippets.

@BBB
Created February 28, 2013 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BBB/5056039 to your computer and use it in GitHub Desktop.
Save BBB/5056039 to your computer and use it in GitHub Desktop.
fabric ubuntu user management
def group_exists(group):
with settings(warn_only=True):
resp = sudo('cat /etc/group | grep %s' % group)
return not str(resp) == ""
def create_group(group):
sudo('groupadd %s' % group)
sudo('echo "%s ALL=(ALL) ALL" >> /etc/sudoers' % group)
def user_exists(user):
with settings(warn_only=True):
resp = sudo('cat /etc/passwd | grep %s' % user)
return not str(resp) == ""
def create_user(user):
sudo('adduser %s --disabled-password --gecos ""' % user)
def add_user_to_group(user, group):
if not group_exists(group):
create_group(group)
if not user_exists(user):
create_user(user)
sudo('adduser %s %s' % (user, group))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment