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

  • 相关阅读:
    mybatis文件映射之select操作返回List集合
    mybatis文件映射之使用#取值时的一些规则
    mybatis文件映射之获取参数值时#和$的区别
    Java之对象池
    Java多线程设计模式(6)两阶段终止模式
    Future和FutureTask
    Java多线程设计模式(3)读写锁模式
    Java中的对象池模式
    创建资源池(对象池)
    Java多线程设计模式之线程池模式
  • 原文地址:https://www.cnblogs.com/reagina/p/6318193.html
Copyright © 2011-2022 走看看