Linux 用户管理(二)

一、groupadd  --create a new group 创建新用户

  • -g  --gid GID

二、groupdel  --delete a group 

三、passwd  --update user's authentication tokens 更改用户密码

  • 主要更改的文件:/etc/shadow 
  • --stdin 

    This option is used to indicate that passwd should read the new
    password from standard input, which can be a pipe.  示例:

  • 案例:批量更改用户密码   批量创建10个用户stu01-stu10,并且设置随机8位密码,要求不能用shell的循环(例如:for,while等),只能用linux命令及管道实现
    • echo stu{01..10}|tr " " "\n"|sed -r 's#(.*)#useradd \1 ; pass=$((RANDOM+10000000)); echo "$pass"|passwd --stdin \1; echo -e "\1 \t `echo "$pass"`">>/tmp/oldboy.log#g'|bash
    • 上述命令实际就是再拼N条下面的命令的组合,举一条命令stu01用户的过程拆解如下:
      useradd stu01 ; 
      pass=$((RANDOM+10000000)); 
      echo "$pass"|passwd --stdin stu01; 
      echo -e "stu01        `echo "$pass"`">>/tmp/oldboy.log
      特别说明:如果用shell循环结构会更简单,之所以限制使用循环的目的是锻炼学生的基础命令运用
      能力,学到现在还没学到SHELL循环课程呢  地址:https://user.qzone.qq.com/49000448/blog/1422183723?_t_=0.5695657615591867
  • -n This will set the minimum password lifetime, in days, if the
    user’s account supports password lifetimes. Available to root
    only. 规定多少天内不能修改密码

  • -x This will set the maximum password lifetime, in days, if the
    user’s account supports password lifetimes. Available to root
    only.规定多少天之后必须修改密码及密码过期时间=当前时间+x

  • -w This will set the number of days in advance the user will begin
    receiving warnings that her password will expire, if the user’s
    account supports password lifetimes. Available to root only. --过期w天之前提醒

  • -i This will set the number of days which will pass before an
    expired password for this account will be taken to mean that the
    account is inactive and should be disabled, if the user’s
    account supports password lifetimes. Available to root only.--密码失效时间即密码过期之后i天失效

  • 示例:账号test01 密码7天之内不能修改,60天之后必须修改,过期7天前提醒,过期10天后失效
    [root@gaogzhen ~]# passwd -n 7 -x 60 -w 7 -i 10  test01
    

四、chage  --change user password expiry information 修改用户密码有效期

  • -i  --list 显示相关信息
  • -E --expiredate 账号过期时间
  • 其他参数功能和passwd相同,可以用passwd 替代

猜你喜欢

转载自www.cnblogs.com/gaogzhen/p/10014963.html