Reputation: 154
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 ?
Upvotes: 2
Views: 1327
Reputation: 154
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) ?
?>
Upvotes: 0
Reputation: 63956
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
Upvotes: 1
Reputation: 11606
This should do:
adduser client1 -p $(perl -e'print crypt("test", "aa")')
Upvotes: 3