1、添加用户
[root@TRAMOMAP ~]# adduser test1 //新建用户test1
[root@TRAMOMAP ~]#passwd test1 //为test1修改密码
Changing password for user test1.
New UNIX password:(123456) //设置新密码为123456
2、添加用户组
[root@TRAMOMAP ~]# groupadd testgroup //新建用户组testgroup
3、查看用户信息
[root@TRAMOMAP ~]#id test1
uid=503(test1) gid=504(test1) groups=504(test1) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@TRAMOMAP ~]#grep test1 /etc/passwd etc/shadow /etc/group
/etc/passwd:test1:x:503:504::/home/test1:/bin/bash
/etc/shadow:test1:!!$l$mc/UeA7v$qaRiYTHKzX0Wbr2of14EE.:16827:0:99999:7:::
/etc/group:test1:x:504:
/etc/group:testgroup:x:505:test1
4、将已有用户添加(移除)用户组
[root@TRAMOMAP ~]# gpasswd –a test1 testgroup //将用户test1添加到用户组testgroup中
[root@TRAMOMAP ~]# id test1
uid=503(test1) gid=504(test1) groups=504(test1) ,505(testgroup) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@TRAMOMAP ~]# gpasswd -d test1 testgroup//将用户test1移除用户组testgroup
Removing user testuser4 from group testgroup
5、新建用户的同时指定用户组
[root@TRAMOMAP ~]# useradd –g testgroup testuser2//新建用户testuser2,并将其添加到用户组testgroup中
[root@TRAMOMAP ~]# id testuser2
uid=504(testuser2) gid=505(testgroup) groups=505(testgroup) context=root:system_r:unconfined_t:SystemLow-SystemHigh
6、临时关闭用户和重新释放
[root@TRAMOMAP ~]#passwd test1 –l
Locking password for user test1
passwd: Success
[root@TRAMOMAP ~]#passwd test1 –u
Unlocking password for user test1
passwd: Success
7、永久性删除用户
[root@TRAMOMAP ~]#userdel testuser3
[root@TRAMOMAP ~]#groupdel testuser3
groupdel: group testuser3 does not exist
[root@TRAMOMAP ~]#usermod –g testuser3 testuser3
usermod: user testuser3 does not exist
[root@TRAMOMAP ~]#id testuser3
id: testuser3: No such user