我们知道在LINUX中 用户的配置文件 主要有 /etc/group  /etc/passwd /etc/shadow

其中/etc/group

NUID=$[`cut -d: -f3 /etc/passwd | grep -v "65534" | sort -n | tail -1`+1]
NGID=$[`cut -d: -f3 /etc/group | grep -v "65534" | sort -n | tail -1`+1]
TODAY=$[`date +"%s"`/86400]

usage() {
  echo -e "\033[31mUsage:\003[0m `basename $0` [-u UID] username"
}

while getopts ":u:" SWITCH ; do
  case $SWITCH in
    u)
    NEWUID=$OPTARG
    cut -d: -f3 /etc/passwd | grep "^$NEWUID" &> /dev/null  && echo "UID exists." && exit 1
    ;;
   \?)
    usage
    exit 1
    ;;
  esac
done

shift $[$OPTIND-1]

if ! cut -d: -f1 /etc/group | grep "^$1" &> /dev/null; then
  echo "$1:x:$NGID:" >> /etc/group
else
  echo "The GROUP $1 exists."
  exit 1
fi

if ! cut -d: -f1 /etc/passwd | grep "^$1" &> /dev/null ; then
  echo "$1:x:${NEWUID:=$NUID}:$NGID::/home/$1:/bin/bash" >> /etc/passwd
  echo "$1:!!:$TODAY:0:99999:7:::" >> /etc/shadow
else
  echo "The user $1 exists."
  exit 1
fi

# home directory
cp -r /etc/skel /home/$1
chown -R $1:$1 /home/$1
chmod -R go=--- /home/$1

#echo '123456' | passwd --stdin $1 &> /dev/null