简体   繁体   中英

Add bash script on linux to create users

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 ?

应该这样做:

adduser client1 -p $(perl -e'print crypt("test", "aa")')

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

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) ? 
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM