用户指令
useradd:创建用户和组
[root@localhost ~]# id
uid=0(root) gid=0(root) 组=0(root) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@localhost ~]# id tom
uid=1000(tom) gid=1000(tom) 组=1000(tom)
[root@localhost ~]# groupadd jerry
[root@localhost ~]# id jerry
id: jerry: no such user
[root@localhost ~]# grep 'jerry' /etc/group
jerry:x:1001:
[root@localhost ~]# tail -1 /etc/passwd
tom:x:1000:1000::/home/tom:/bin/bash
[root@localhost ~]# useradd -u 1001 -g 1001 -G tom -c "I'm boss." -d /opt/test -s /bin/bash hzw
[root@localhost ~]# id hzw
uid=1001(hzw) gid=1001(jerry) 组=1001(jerry),1000(tom)
[root@localhost ~]# grep hzw /etc/group
tom:x:1000:hzw
查看bash配置文件
[root@localhost ~]# su - hzw
[hzw@localhost ~]$ ls -a
. .. .bash_logout .bash_profile .bashrc
[hzw@localhost ~]$ exit
登出
userdel:删除用户
[root@localhost ~]# ll /opt/
总用量 0
drwx------. 2 hzw jerry 59 9月 18 23:11 test
[root@localhost ~]# userdel -r hzw
[root@localhost ~]# grep hzw /etc/passwd
[root@localhost ~]# grep hzw /etc/group
[root@localhost ~]# ll /opt/
总用量 0
不能在已有的目录上创建用户目录
[root@localhost ~]# mkdir /opt/hehe
[root@localhost ~]# useradd -d /opt/hehe hzw
useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件。
[root@localhost ~]# ll /opt/hehe/ -a
总用量 0
drwxr-xr-x. 2 root root 6 9月 18 23:13 .
drwxr-xr-x. 3 root root 17 9月 18 23:13 ..
[root@localhost ~]# su - hzw
-bash-4.2$
id -u/-g/-G:查看用户/基本组/附加组的ID
[hzw@localhost ~]$ id hzw
uid=1001(hzw) gid=1002(hzw) 组=1002(hzw)
[hzw@localhost ~]$ id -u
1001
[hzw@localhost ~]$ id -g
1002
[hzw@localhost ~]$ id -G
1002
usermd -a -G将用