Results 1 to 5 of 5

Thread: adduser bash script

  1. #1
    Join Date
    Oct 2006
    Beans
    Hidden!

    adduser bash script

    I am a newbee in linux and scripting in general. I am trying to add a user to my ubuntu box by running a script which provides username, and other stuff. What i have managed to do is to execute the script and the user is added (writing stuff to /etc/password and /etc/shadow), at the end the script then tries to initialise the password for the user (using : passwd $username). **** this is where my problem is ****.

    The issue is i dont want to type the password. i just want to send it as a parameter.

    Is there any way to add user and apply password by executing the script?

    Is it possible to run this script say from a web interface (php etc) where an admin capture user details and by submitting the form the user is added?

  2. #2
    Join Date
    May 2006
    Beans
    1,790

    Re: adduser bash script

    Quote Originally Posted by chi_n_z View Post
    I am a newbee in linux and scripting in general. I am trying to add a user to my ubuntu box by running a script which provides username, and other stuff. What i have managed to do is to execute the script and the user is added (writing stuff to /etc/password and /etc/shadow), at the end the script then tries to initialise the password for the user (using : passwd $username). **** this is where my problem is ****.

    The issue is i dont want to type the password. i just want to send it as a parameter.

    Is there any way to add user and apply password by executing the script?

    Is it possible to run this script say from a web interface (php etc) where an admin capture user details and by submitting the form the user is added?
    You can combine "mkpasswd -s" with "usermod -p". Look at their man pages.

  3. #3
    Join Date
    Oct 2006
    Beans
    Hidden!

    Angry Re: adduser bash script

    Quote Originally Posted by Arndt View Post
    You can combine "mkpasswd -s" with "usermod -p". Look at their man pages.


    I have tried the options u gave me. But with no luck. I am not sure if i am doing it right.

    As u suggested. http://expect.nist.gov/example/mkpasswd.man.html#sect5
    mkpasswd generates passwords and can apply them automatically to users.

    But i couldn't manage to solve the problem i am not exactly sure how shld i combine mkpasswd and usermod to achieve my goal

  4. #4
    Join Date
    May 2006
    Beans
    1,790

    Re: adduser bash script

    Quote Originally Posted by chi_n_z View Post


    I have tried the options u gave me. But with no luck. I am not sure if i am doing it right.

    As u suggested. http://expect.nist.gov/example/mkpasswd.man.html#sect5
    mkpasswd generates passwords and can apply them automatically to users.

    But i couldn't manage to solve the problem i am not exactly sure how shld i combine mkpasswd and usermod to achieve my goal
    Your first problem was that 'passwd' reads from the terminal, not from standard input, so you can't easily send a password to it with a script (but the program 'expect' may help if you really need to use 'passwd'). "usermod -p" takes an encrypted password as argument, so that should solve that problem. But now you need to encrypt the password before giving it to 'usermod', and 'mkpasswd' does that.

    I think this ought to work for you, but I haven't tried it:

    # Assuming $password and $username are available
    tmpdir=/tmp/pwddir$$
    chmod og-rx $tmpdir
    echo $password > $tmpdir/pwd
    encrypted=`mkpasswd -s < $tmpdir/pwd`
    usermod -p $encrypted $user
    rm -rf $tmpdir
    This complexity is needed to ensure that the password is never visible in cleartext to anyone else. There may be an easier way to do it I have missed.

    encrypted=`echo $password | mkpasswd -s`
    looks a lot simpler, but I'm not sure that this will not result in the 'echo' command being visible in the process listing.

  5. #5
    Join Date
    Oct 2006
    Beans
    Hidden!

    Re: adduser bash script

    Thanx a lot man, your code did the magic! Just after adding
    mkdir /tmp/pwddir. At least I am sorted on this one, I now have to take care of adding the user from a web interface.


    Quote Originally Posted by Arndt View Post

    password="my_simple password"
    login="a_system_user created before"

    mkdir /tmp/pwddir
    tmpdir=/tmp/pwddir
    chmod og-rx $tmpdir
    echo $password > $tmpdir/pwd
    encrypted=`mkpasswd -s < $tmpdir/pwd`
    usermod -p $encrypted $login
    rm -rf $tmpdir

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •