zoukankan      html  css  js  c++  java
  • SHELL之手工创建账号

    思路:

    涉及到的文件:

    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、家目录

    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、口令

    echo “123” | passwd --stdin $ACCOUNT

    执行脚本时,遇到错误的时候最好打开调试开关:bash -x 脚本文件,或者在脚本中可能出现错误的地方添加一条 set -x 指令。

    [root@localhost ~]# 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 500 ];then
    MAXUID=500
    fi

    #!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 500 ];then
    MAXUID=500
    fi

    MAXGID=`cut -f4 -d: /etc/passwd |sort -n |tail -n 2 |head -n 1`
    if [ $MAXGID -lt 500 ];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

  • 相关阅读:
    锐捷交换机密码恢复
    adobe cs3系列产品官方帮助网页(中文)
    网页设计视频教程
    锐捷交换机、路由器配置手册
    WINPE下如何直接删除联想隐藏分区?
    IWMS实现频道页面的方法
    SATA、SCSI、SAS区别与特点
    自定义系统必备
    自己写的Web服务器
    尝试MVP模式
  • 原文地址:https://www.cnblogs.com/reagina/p/6318193.html
Copyright © 2011-2022 走看看