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