|
May
07
|
#!/bin/bash
HOME_BASE=”/home/” #set your home base directory
SHELL=”/bin/bash” #set shell for users
#checking if you are root
if [ $(id -u) -eq 0 ]; then
read -p “Username:” USER
read -s -p “Password:” PASSWORD
egrep -w “^$USER” /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo -e “\n$USER exists!\n”
exit 1
else
PASS=$(perl -e ‘print crypt($ARGV[0], “password”)’ $PASSWORD)
useradd -p ${PASS} -s $SHELL -m -d ${HOME_BASE}${USER} ${USER}
[ $? -eq 0 ] && echo -e “\nUser has been added to system!\n” || echo -e “\nFailed to add a user!\n”
fi
else
echo -e “\nOnly root may add a user to the system\n”
exit 2
fi
save it like script.sh and run it with: ./script.sh
Recent Comments