Last active
August 29, 2015 14:12
-
-
Save elifiner/cf757e3a56c25f87a4a2 to your computer and use it in GitHub Desktop.
Fabric script to properly set up a user on a remote Ubuntu.
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
from crypt import crypt | |
from fabric.api import * | |
from fabric.contrib.files import append, uncomment | |
env.user = 'root' | |
env.use_ssh_config = True | |
def create_user(name, password): | |
with hide('stdout'): | |
run('useradd -m %s' % name) | |
run('usermod --password %s %s' % (crypt(password, 'salt'), name)) | |
run('mkdir -p ~%s/.ssh' % name) | |
run('cp ~/.ssh/authorized_keys ~%s/.ssh' % name) | |
run('chown -R %s:%s ~%s/.ssh' % (name, name, name)) | |
run('chsh -s /bin/bash %s' % name) | |
run('cp /etc/sudoers /tmp/sudoers.new') | |
append('/tmp/sudoers.new', '%s ALL=NOPASSWD: ALL' % name, use_sudo=True) | |
run('visudo -c -f /tmp/sudoers.new') | |
run('EDITOR="cp /tmp/sudoers.new" visudo') | |
uncomment('~%s/.bashrc' % name, '#force_color_prompt=yes') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment