0

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

1 Answers1

1

adduser is just a Debian/Ubuntu-specific front-end to the more normal useradd command, which takes a variety of options on the command line, including a pre-hashed password as its -p option. For this you should probably be calling useradd with the desired options instead of adduser.

On most other Linux distributions, adduser is simply symlinked to useradd, or absent entirely.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Thanks, this might come in handy for anyone else reading the question/answer http://serverfault.com/questions/367559/how-to-add-a-user-without-knowing-the-encrypted-form-of-the-password – BrainLikeADullPencil Jul 27 '14 at 00:45