I'm using this Fabric function to try to add a user to a Ubuntu server. It's not throwing an error, but I can't login with the user that I'm trying to add after the script's finished. If I add a user manually, after I run the adduser myusername
command, I get prompted twice to enter a password. In this script, the repeated prompt (as I call it) is being dealt with (uneffectively, I believe) by passing the password twice to this echo command
if not sudo("adduser %s | echo -e '%s\n%s\n'" % (new_user,passwd,passwd)).failed:
Can you explain how that would more appropriately be dealt with in this function?
def user_add(new_user, passwd=False):
"""Add new user"""
with settings(hide('running', 'stdout', 'stderr'), warn_only=True):
# if is_host_up(env.host):
if not passwd:
passwd = generate_passwd()
if not sudo("adduser %s | echo -e '%s\n%s\n'" % (new_user,passwd,passwd)).failed:
run('echo "{user} ALL=(ALL:ALL) ALL" >> /etc/sudoers'.format(user=new_user))
...other code not included