首页 > 系统服务 > 详细

Linux 用户管理(二)

时间:2018-11-25 12:35:54      阅读:164      评论:0      收藏:0      [点我收藏+]

一、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 替代

 

Linux 用户管理(二)

原文:https://www.cnblogs.com/gaogzhen/p/10014963.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!