Results 1 to 2 of 2

Thread: chpasswd in sudoers

Hybrid View

  1. #1
    Join Date
    Nov 2010
    Beans
    3

    chpasswd in sudoers

    I've searched everywhere I can think of, and am not able to get this to work. I need to add the user "www-data" to the sudoers file to run two commands with no password, namely "/usr/sbin/useradd" and "usr/sbin/chpasswd". I need this for a script that will automatically create a user and set their password. the line I'm using in the sudoers file is below. I've tested removing the useradd references, and the script fails. However, I can't get the chpasswd command to work without the password.

    sudoers line
    Code:
    www-data hostname=NOPASSWD: /usr/sbin/useradd, /usr/sbin/chpasswd
    test.sh
    Code:
    #!/bin/sh
    sudo useradd -m $1
    echo 1 - user added
    sudo echo "$1:$2" | chpasswd
    echo 2 - pass changed

  2. #2
    Join Date
    Nov 2010
    Beans
    3

    Talking Re: chpasswd in sudoers

    Just to wrap this up, I found a workaround. Instead of using the chpasswd command, I tweaked it to use mkpasswd in the useradd statement, as below. Cheers!

    Code:
    sudo useradd -p $(mkpasswd -s -m sha-512 $password) -m $username

Tags for this Thread

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
  •