锁定用户
注意:锁定用户密码后 root 权限仍然可以 su 切换到该用户。
usermod -L admin
passwd -l admin
解锁用户
usermod -U admin
passwd -u admin
添加账号描述
usermod -c 'PHP Admin' admin
账号永不过期
usermod -e -1 admin
chage -E -1 admin
密码永不过期
chage -M 99999 admin
passwd -x 99999 admin
强制账号过期
注意:账号过期将无法登陆,一般用于临时账号使用时间限制。
usermod -e $(date +%Y-%m-%d -d '1 day ago') admin
chage -E $(date +%Y-%m-%d -d '1 day ago') admin
强制密码过期
注意:密码永不过期下次登陆时也会提示更改密码,一般用于初始化用户密码。
passwd -e admin
指定密码更改时间
chage -d $(date +%Y-%m-%d) admin
查看账号及密码状态
[root@WEB1 ~]# chage -l admin
[root@WEB1 ~]# passwd -S admin
[root@WEB1 ~]# for id in $(cut -d':' -f1 /etc/passwd); do id $id | cut -d' ' -f'1-3' >>/tmp/ListID; done; printf "%-30s %-30s %s\n" $(cat /tmp/ListID) | nl && rm -f /tmp/ListID
[root@WEB1 ~]# for id in $(cut -d':' -f1 /etc/passwd); do printf "%-20s %s %s%s %s \t %s %s%s %s\n" $id $(chage -l $id | grep -E 'Password expires|Account expires')>>/tmp/ListEX; done; nl /tmp/ListEX && rm -f /tmp/ListEX
[root@WEB1 ~]# for id in $(cut -d':' -f1 /etc/passwd); do printf "%-20s %3s %11s %3s %6s %3s %3s %s %s %s %s %s\n" $(passwd -S $id)>>/tmp/ListPS; done; nl /tmp/ListPS && rm -f /tmp/ListPS