Ideas:
Documents related to:
1,/etc/passwd
echo "$ACCOUNT: x:$[$MAXUID +1]:$[$MAXGID +1]::/home/$ACCOUNT:/bin/bash" >>/etc/passwd
2,/etc/shadow
chmod U+w/etc/shadow
echo "$ACCOUNT::::::::" >>/etc/shasow
chmod u-w/etc/shadow
3,/etc/group
echo "$ACCOUNT: x:$[$MAXGID +1]:" >>/etc/group
4. Home Directory
mkdir/home/$ACCOUNT
Cp-a/etc/skel/. /home/$ACCONT
Chown-r $ACCOUNT: $ACCOUNT/home/$ACCOUNT
chmod 700/home/$ACCOUNT
5. MAIL
touch/var/spool/mail/$ACCOUNT
chmod 660/var/spool/mail/$ACCOUNT
Chown $ACCOUNT: mail/var/spool/mail/$ACCOUNT
6. Password
echo "123" | passwd--stdin $ACCOUNT
When executing a script, it is a good idea to open the debug switch when encountering an error: bash-x the script file, or add a set-x instruction where the error may occur in the script.
[Email protected] ~]# vim useradd.sh
#!bin/bash
Read-p "Please input one user:" Account
Grep-q $ACCOUNT/etc/passwd && echo "The user $ACCOUNT is exist" && exit
#test current Max UID and GID
Maxuid= ' cut-f3-d:/etc/passwd |sort-n |tail-n 2 |head-n 1 '
If [$MAXUID-lt];then
maxuid=500
Fi
#!bin/bash
Read-p "Please input one user:" Account
Grep-q $ACCOUNT/etc/passwd && echo "The user $ACC Ount is exist "&& exit
#test current Max uid and GID
maxuid= ' cut-f3-d:/etc/passwd |sort-n |tail-n 2 |he Ad-n 1 '
If [$MAXUID-lt];then
maxuid=500
Fi
Maxgid= ' cut-f4-d:/etc/passwd |sort-n |tail-n 2 |head-n 1 '
If [$MAXGID-lt];then
maxgid=500
Fi
#change/etc/passwd
echo "$ACCOUNT: x:$[$MAXUID +1]:$[$MAXGID +1]::/home/$ACCOUNT:/bin/bash" >>/etc/passwd
#change/etc/shawdow
chmod U+w/etc/shadow
echo "$ACCOUNT::::::::" >>/etc/shadow
chmod u-w/etc/shadow
#change/etc/group
echo "$ACCOUNT: x:$[$MAXGID +1]:" >>/etc/group
#create Home Dir
mkdir/home/$ACCOUNT
Cp-a/etc/skel/. /home/$ACCOUNT
Chown-r $ACCOUNT: $ACCOUNT/home/$ACCOUNT
chmod 700/home/$ACCOUNT
#create User Mailbox
touch/var/spool/mail/$ACCOUNT
chmod 660/var/spool/mail/$ACCOUNT
Chown-r $ACCOUNT: mail/var/spool/mail/$ACCOUNT
#change User passwd
echo "123" |PASSWD--stdin $ACCOUNT &>/dev/null
Shell create an account manually