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天后失效
[[email protected] ~]# passwd -n 7 -x 60 -w 7 -i 10 test01
四、chage --change user password expiry information 修改使用者密碼有效期
- -i --list 顯示相關資訊
- -E --expiredate 賬號過期時間
- 其他引數功能和passwd相同,可以用passwd 替代