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

  • 相关阅读:
    2018年11月1日开通博客园感想!
    Aspnet MVC 异步调用
    AspNet WebApi : MessageHandler(消息处理器 )
    AspNet MVC : 操作/控制器过滤器(action filter)
    PHP 面向对对象基础(接口,类)
    原生Ajax + Promise
    基于Qt QGraphicsView的多点触摸绘图
    node应用通过multer模块实现文件上传
    AspNet WebApi: 了解下HttpControllerDispatcher,控制器的创建和执行
    视频投影(二维视频投影到三维模型上)
  • 原文地址:https://www.cnblogs.com/reagina/p/6318193.html
Copyright © 2011-2022 走看看