READHAT7 RHCSA学习笔记 账号管理与ACL权限设置

和账号信息相关的三个文件

/etc/password

用户名:密码(存在于shadow文件中):UID:GID:用户描述信息:用户的家目录:用户所能使用的shell是什么样的环境

[root@localhost ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
lalin:x:1000:1000:lalin:/home/lalin:/bin/bash

/etc/shadow

用户名:加密后的密码

[root@localhost ~]# cat /etc/shadow
root:$6$fOY5G5pE0/VJlhAA$hlfNhg7oUuuHAD/aNYAVrki7GMxGxXm.hmeBEvjqD6r0.JUux0WYMprkoS4uNfCi6/RZLYfnRQS1gOXpUB.iA1::0:99999:7:::
bin:*:16925:0:99999:7:::
daemon:*:16925:0:99999:7:::
adm:*:16925:0:99999:7:::
lp:*:16925:0:99999:7:::
sync:*:16925:0:99999:7:::
shutdown:*:16925:0:99999:7:::
halt:*:16925:0:99999:7:::
mail:*:16925:0:99999:7:::
operator:*:16925:0:99999:7:::
games:*:16925:0:99999:7:::
ftp:*:16925:0:99999:7:::
nobody:*:16925:0:99999:7:::
systemd-bus-proxy:!!:18368::::::
systemd-network:!!:18368::::::
dbus:!!:18368::::::
polkitd:!!:18368::::::
abrt:!!:18368::::::
tss:!!:18368::::::
postfix:!!:18368::::::
sshd:!!:18368::::::
lalin:$6$..WCA1bxnM4vieRc$xO.Pgi/.gpXZo1FsCqrVrlK3ZVkDOmVH8KCKxGu5W8dhYdEe7Sgd0CWSo8PmSNYeFKF7scFXuEKGs54ycCNc91::0:99999:7:::

/etc/group

组名:组密码:组ID:有哪些用户存在于这个组里面

[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:30:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
utmp:x:22:
utempter:x:35:
ssh_keys:x:999:
input:x:998:
systemd-journal:x:190:
systemd-bus-proxy:x:997:
systemd-network:x:192:
dbus:x:81:
polkitd:x:996:
cgred:x:995:
abrt:x:173:
tss:x:59:
dip:x:40:
postdrop:x:90:
postfix:x:89:
sshd:x:74:
lalin:x:1000:lalin

id命令

id 查看当前用户的uid、gid、groups

id username 查看指定用户的uid、gid、groups

[root@localhost ~]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@localhost ~]# id lalin
uid=1000(lalin) gid=1000(lalin) groups=1000(lalin)

有效群组与储户群组

在/etc/password中看到的gid就叫做有效群组

一个用户如果在多个组中,则该用户拥有多个所属组的权限

当用户创建文件时候,创建文件所属的组文用户的初始组

useradd 创建用户

useradd username 创建一个用户,用户名为username,所属组为username

useradd -u 创建用户的时候指定用户的uid

useradd -n 创建用户的时候指定用户的家目录

useradd -g 创建用户的时候指订用户的所属组(初始组)

useradd -G 指定用户的附属组

useradd -s 指定用户的工作环境(shell)

[root@localhost ~]# useradd -u 111 -g root -G lalin test

passwd  为创建的用户指定密码

[root@localhost ~]# passwd test
Changing password for user test.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

创建账号静止登录

[root@localhost ~]# useradd -s /sbin/nologin test2
[root@localhost ~]# su test2
This account is currently not available.

删除账号

userdel username 删除账号但是不删除家目录

userdel -r username 删除账号并且删除家目录

[root@localhost ~]# userdel test2
[root@localhost ~]# id test2
id: test2: no such user

删除组

[root@localhost ~]# groupdel test

账户修改

usermod -u 修改用户的时候指定用户的uid

usermod -n 修改用户的时候指定用户的家目录

usermod -g 修改用户的时候指订用户的所属组(初始组)

usermod -G 修改用户的附属组

usermod -s 修改用户的工作环境(shell)

[root@localhost ~]# usermod -u 112 test
[root@localhost ~]# id test
uid=112(test) gid=0(root) groups=0(root),1000(lalin)
[root@localhost ~]# usermod -s  /sbin/nologin test
[root@localhost ~]# usermod -g lalin test
[root@localhost ~]# id tets
id: tets: no such user
[root@localhost ~]# id test
uid=112(test) gid=1000(lalin) groups=1000(lalin)
[root@localhost ~]# usermod -G root test
[root@localhost ~]# id test
uid=112(test) gid=1000(lalin) groups=1000(lalin),0(root)

查看系统中支持的shell文件

chsh -l

[root@localhost ~]# chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin

改变用户的shell环境

chsh -s path username

[root@localhost ~]# chsh -s /sbin/nologin test
Changing shell for test.
Shell changed.
[root@localhost ~]# su test
This account is currently not available.

用户组管理员

为组增加密码 gpasswd groupname

[root@localhost ~]# gpasswd  testgroup
Changing the password for group testgroup
New Password: 
Re-enter new password: 

添加用户组管理员 gpasswd -A username groupname

[root@localhost ~]# gpasswd -A test testgroup

为用户组中添加用户 gpasswd -a username groupname

[root@localhost ~]# gpasswd -a test2 testgroup
Adding user test2 to group testgroup

主机权限的细化 ACL

对于文件系统传统的权限有 owner group others 搭配有三种权限 r w x 并没有办法针对某一个使用者或者某一个群组来指定特定的权限

ACL r w x 权限之外进行更加细化的权限设定的技术 ACL可以

针对单一使用者 组 来进行权限设置 对于需要特殊权限的使用情况非常有帮助

ACL 可以针对以下几个方面来进行权限控制

使用者

群组

默认属性 mask

ACL的设定需要有文件系统

的支持 目前大部分的文件系统都支持ACL

修改用户acl

[root@localhost tmp]# su test2
[test2@localhost tmp]$ cd testacl
bash: cd: testacl: Permission denied
[test2@localhost tmp]$ su root
Password: 
[root@localhost tmp]# setfacl -m u:test2:rx /tmp/testacl
[root@localhost tmp]# su test2
[test2@localhost tmp]$ cd testacl/
[test2@localhost testacl]$ 

 查看文件的acl权限

[root@localhost testacl]# getfacl /tmp/testacl/
getfacl: Removing leading '/' from absolute path names
# file: tmp/testacl/
# owner: root
# group: root
user::rwx
user:test2:r-x
group::rwx
mask::rwx
other::---

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值