2

I ask for your help to create a script to create a user and a password on 1 click

useradd client1 -M -s /bin/false
passwd client1

To have for instance a new user with:

login: client1 password: test

Is it possible ? and if it is, how please ?

3 Answers 3

3

This should do:

adduser client1 -p $(perl -e'print crypt("test", "aa")')
Sign up to request clarification or add additional context in comments.

3 Comments

No, the -p parameter expects the password encrypted, says the documentation. Read reference from my answer above.
Hehe. I don't know a thing about Perl but what you did there is cool. I didn't know it was possible but I wonder what crypto algorithm will it use? Will work for sure?
It just generates a crypt of password "test" with salt "aa". The salt can be any two characters and will be carried over to the first two characters of the password too.
1

man useradd will give you hints to do this and I believe this is how:

useradd [username] -d /path_to_home_directory -p [encrypted_password]

now, VERY IMPORTANT, the documentation for useradd says that the -p parameter expects the password ENCRYPTED as returned by crypt(7); therefore, what you need to do is create a sample user with password "test" for example, then open up /etc/shadow and copy and paste the password from the file and use it on your script.

Suppose that "test" encrypted in /etc/shadow appears as "zxs1@431sa" your final script should be:

useradd [username] -d /path_to_home_dir -p zxs1@431sa [enter]

That should do it, I think.

References: http://linux.die.net/man/8/useradd

Comments

0

Ok I find it :

First Script create user: (add_user.sh)

#!/bin/sh
useradd $1 -M -s /bin/false

Second one create a password or change it:

#!/bin/sh
echo "$1:$2" | chpasswd

Do you know how i can call this script from php file ?

<?php
    Execution (add_user.sh) ? 
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.