liunx系统中,每个用户都属于一个用户(属主)和一个用户组(属组),通过ll | stat 查看用户属主和属组或者通过 stat -c %G+文件名查看所属主
1.1用户分类
根据帐号的功能:超级用户(root) UID:0
普通用户又分下面两种:
系统用户 UID:1-999 rhel6中是1-499,它一般是系统内建的账号,不用于登录操作系统,它主要是为了满足自身系统管理需要而建,也叫伪用 户
伪用户:与系统和程序服务有关,比如:bin、daemon、通常不需要或无法登录系统,可以没有宿主目录
本地用户 UID:1000+ rhel6 中是500以上,也叫自定义用户,由root管理员创建,供用户登陆进行操作
说明:UID即每个用户的身份标示,类似于每个人的身份证号码.
1.1.1配置文件
1.2 用户相关命令
(1)添加用户
useradd [参数] 用户名
常用参数
q -u UID
q -d 宿主目录
q -g 起始组(主组) #只能有一个
q -G 附加组 #可以有多个
q -s 登陆shell
[root@hostline /]# useradd xuesheng
[root@hostline /]# id xuesheng
uid=1005(xuesheng) gid=1006(xuesheng) 组=1006(xuesheng)
[root@hostline /]# grep xuesheng /etc/passwd
xuesheng:x:1005:1006::/home/xuesheng:/bin/bash
说明:用户的全部信息保存在 etc/password中,
1.2.1指定用户UID
[root@hostline /]# useradd -u 1100 xueba
[root@hostline /]# ls /home
caichunfeng caichunfeng1 hello work world xueba xuesheng
[root@hostline /]# tail -2 /etc/passwd
xuesheng:x:1005:1006::/home/xuesheng:/bin/bash
xueba:x:1100:1100::/home/xueba:/bin/bash
1.2.2指定用户宿主目录
useradd -d /tmp/xuegod-3 xuegod-3
还可以指定用户起始组,附加组
1.3删除用户
userdel [参数] 用户名
-r 删除用户,同时删除用户家目录和mailspool下的用户目录
[root@hostline home]# ls
caichunfeng caichunfeng1 hello work world xueba xuesheng
[root@hostline home]# userdel -r xuesheng
[root@hostline home]# ls
caichunfeng caichunfeng1 hello work world xueba
1.4密码文件
[root@hostline home]# tail -4 /etc/passwd
world:x:1004:1005::/home/world:/bin/bash
xueba:x:1100:1100::/home/xueba:/bin/bash
xuezha:x:1101:1101::/test/home:/bin/bash
xuexi:x:1102:1102::/test/home:/bin/bash
[root@hostline home]# tail -4 /etc/shadow
world:$6$3OkPRfSf$BdvO13yMJIotQQH7BIImJiUCtBrpftPG3gvkyopcv2iGzrN4JM9l7/j6hgl1qrdefMD2TqflyhaoiaeJ8lQrt/:17311:0:99999:7:::
xueba:!!:17337:0:99999:7:::
xuezha:!!:17337:0:99999:7:::
xuexi:!!:17337:0:99999:7:::
[root@hostline home]# grep work /etc/shadow
systemd-network:!!:17303::::::
[root@hostline home]# grep xueba /etc/shadow
xueba:!!:17337:0:99999:7:::
1.4修改用户信息
常用参数:
q -u UID
q -d 宿主目录
q -g 起始组 #只能有一个
q -G 附加组 #可以有多个
q -s 登录shell
q -L 锁定
[root@hostline home]# tail -1 /etc/passwd
xuexi:x:1102:1102::/test/home:/bin/bash
[root@hostline home]# mkdir /test/bash
[root@hostline home]# usermod -s /etc/passwd /test/bash
[root@hostline home]# usermod -s /etc/passwd hello
[root@hostline home]# tail -1 /etc/passwd
xuexi:x:1102:1102::/test/home:/bin/bash
2.1组分类
根据帐号的功能:超级用户组(root) GID:0
普通用户组
系统用户组 GID:1-999 redhat6 是1-499
本地用户 组 GID:1000+ redhat6 是500+
[root@hostline home]# tail -5 /etc/group
hello:x:1004:
world:x:1005:
xueba:x:1100:
xuezha:x:1101:
xuexi:x:1102: