usermod 命令的选项和 useradd 差很少。
一个用户能够属于多个组,可是gid只有一个;除了gid,其余的组(groups)叫作扩展组。shell
usermod -u 1010 username # 更改用户id usermod -g 1008 username # 更改用户的组id。 -g 后面能够是组名或组id usermod -d /home/test username # 更改家目录 usermod -s /sbin/nologin username # 指定shell usermod -G testgrp username # 更改扩展组,多个扩展组用逗号分开 usermod -G testgrp1, testgrp2 username [root@centos01 ~]# id test01 #查看用户的id及组id uid=1001(test01) gid=1001(test01) groups=1001(test01) [root@centos01 ~]# id test06 uid=1006(test06) gid=1006(test06) groups=1006(test06) [root@centos01 ~]# usermod -G test03,grouptest01 test06 [root@centos01 ~]# id test06 uid=1006(test06) gid=1006(test06) groups=1006(test06),1003(grouptest01),1004(test03)
用户的密码是空密码或锁定的密码时,该用户不能登陆centos
passwd # 更改当前用户用户的密码 passwd username # 更改username用户的密码 [root@centos01 ~]#cat /etc/shadow ... bin:*:16231:0:99999:7::: # 第二段密码位为*,表示密码被锁定了 test03:!!:17794:0:99999:7::: # 第二段密码位为叹号(!!),表示密码为空 ... passwd -l username # 锁定用户username的 usermod -L username # 一样锁定用户 passwd -u username # 解锁
passwd --stdin username # 新密码经过标准输入 echo "123111" | passwd --stdin username # 经过管道和passwd标准输入选项改密码 echo -e "123\nsss" # 转义输出 echo "123111\n123111" |passwd username # 经过管道换行输入改密码
用来生成密码的工具, 安装: yum install -y expect工具
[root@centos01 ~]# mkpasswd # 默认长度为9的密码 UP-aaw23u [root@centos01 ~]# mkpasswd -l 12 # 指定长度为12的密码 qakLsj79Nho= [root@centos01 ~]# mkpasswd -l 12 -s 3 # 指定长度为12,特殊字符有3个的密码 vk[|s7LckO5~ [root@centos01 ~]# mkpasswd -l 12 -s 0 # 指定长度为12,特殊字符有0个的密码 dYsdul8lsrZ0