Shell create an account manually

Source: Internet
Author: User
Tags stdin

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.