Last active
December 29, 2015 11:08
-
-
Save gmiroshnykov/7661240 to your computer and use it in GitHub Desktop.
fab create_user
This file contains hidden or 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 fabric.api import * | |
# Usage: fab -H <hostname> -u <ssh_username> create_user:<username> | |
def create_user(username): | |
run('adduser --disabled-password --gecos "" {0}'.format(username)) | |
run('echo "{0} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/{0}'.format(username)) | |
run('chmod 0440 /etc/sudoers.d/{0}'.format(username)) | |
run('mkdir -p /home/{0}/.ssh'.format(username)) | |
run('chmod 0755 /home/{0}/.ssh'.format(username)) | |
run('chown {0}:{0} /home/{0}/.ssh'.format(username)) | |
run('cp ~/.ssh/authorized_keys /home/{0}/.ssh/authorized_keys'.format(username)) | |
run('chmod 0644 /home/{0}/.ssh/authorized_keys'.format(username)) | |
run('chown {0}:{0} /home/{0}/.ssh/authorized_keys'.format(username)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment