好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

RHEL6上课笔记之acl

Passwd,shadow,gshadow,group 这四个文件是 PAM ( portable authentication module )的数据库。 pam 的文件都是 (.so) 结尾的。 cd /lib64/security 目录中有很多 .so 的文件。其中到迄今为止都没有 bug 的是 pam_unix.so , pam_userdb.so 是的 pam_unix.

Passwd,shadow,gshadow,group 这四个文件是 PAM ( portable authentication module )的数据库。

pam 的文件都是 (.so) 结尾的。

cd /lib64/security 目录中有很多 .so 的文件。其中到迄今为止都没有 bug 的是 pam_unix.so , pam_userdb.so 是的 pam_unix.so 助手。

PAM 的配置文件在 /etc/pam.d/ 下。现在我们来看其中的一个配置文件 etc/pam.d/login/ 。

login 中有四类

auth :密码正确性。

passwd :密码最多能用的时间。

account :帐号是否合法。

session :性能(如,分配多少 cpu )。

其中有一行是:

account required (必要条件 ) pam_nologin.so

在 etc 目录下 touch 一个名为 nologin 的文件,那么用除 root 以外的用户登入就会提示 [ 鉴定错误 ] (免打扰模式)。 删掉就恢复正常。

单单针对 root 的 tty :

不让 root 在某个 tty 窗口登入。可以配置 /etc/securetty 的白名单配置文件。例如:如果不想让 root 在 tty4 登入,那么就在 securetty 白名单中把 tty4 注释掉。

也可以阻止其它用户在某个 tty 登入。需要配置 /etc/security/access.conf 配置文件。配置方法如下:

#-:ALL EXCEPT (wheel) shutdown sync:LOCAL

- : gg : tty4 # 不让 gg 用户在 tty4 上登入,其它 tty 可以。(也可以在这里配置 root )。配置完 access.conf 文件后还需要配置一个文件,就是在 /etc/pam.d/login 文件中加上一句: account required pam_nologin.so

acl :对文件设置 acl

给文件添加第二属主。

使用 root 用户在 tmp1 下

[root@station10 tmp1]# echo [helo body] >> file

[root@station10 tmp1]# getfacl file (查看文件属主)

# file: file

# owner: root

# group: root

user::rw-

group::r--

mask::r--

other::r--

[root@station10 tmp1]# su - eg

[eg@station10 ~]$ cd /root/tmp1/

[eg@station10 tmp1]$ echo 111 >> file

-bash: file: 权限不够

[root@station10 tmp1]# setfacl -m u:eg:rw file ( -m 修改。用户:用户名:权限)

[root@station10 tmp1]# getfacl file

# file: file

# owner: root

# group: root

user::rw-

user:eg:rw- #eg 用户

group::r--

mask::rw-

other::r--

[root@station10 tmp1]# su - eg

[eg@station10 ~]$ echo xxx >> /root/tmp1/file

[eg@station10 ~]$ cat /root/tmp1/file

helo body

xxx

在做以上实验时如果在执行 setfacl -m u:eg:rw file 的时候提示 不支持的操作,那是因为分区不具备 acl 品质。那么就需要给分区添上 acl 的品质。如下:

[root@station10 tmp1]# tune2fs -l /dev/sda3

……

Default mount options: user_xattr acl # 具备 acl 品质

……

如果没有该品质那么就要给它加上。第 1 种方式: [ tune2fs -o acl /dev/sda3 [ 添上。第二种方式:使用手工 mount -o alc /dev/sda3 。第三种方式:开机自动挂载上,配置 fstab 如下图 : 使用 mount -a 验证。 Mount 查看是否具有 acl 品质。


defaults 后面可以有 (noexec,nodev) 参数。当然这些参数也可以在挂载的时候写上或则 fstab 都行。

noexec :如果加了此参数那么在该分区就不能够使用( ./ ) 执行任何可执行文件。就会提示权限不够。

nodev :???

[root@station10 tmp1]# mknod egfile b 8 7

[root@station10 tmp1]# mount egfile /mnt1

/tmp1/egfile 99M 5.6M 89M 6% /mnt1

/dev/sda7 99M 5.6M 89M 6% /mnt

acl :对目录设置 acl

我们新建一个文件夹,然后使用刚刚对文件增加第二属主的方式来做。如下:

[root@station10 /]# mount /dev/sda7 /mnt

[root@station10 mnt]# mkdir dir

[root@station10 mnt]# getfacl dir/

# file: dir/

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

[root@station10 mnt]# setfacl -m u:eg:rwx dir

setfacl: dir: 不支持的操作 # 由于刚刚挂载的时候没有添加 acl 品质的结果(一定要注意,如果没有 acl 品质那么就不能做 acl 。)

[root@station10 mnt]# tune2fs -o acl /dev/sda7

[root@station10 mnt]# tune2fs -l /dev/sda7

……

Default mount options: acl # 有了

……

[root@station10 /]# umount /mnt

[root@station10 /]# mount /dev/sda7 /mnt

[root@station10 mnt]# setfacl -m u:eg:rwx dir

[root@station10 mnt]# getfacl dir/

# file: dir/

# owner: root

# group: root

user::rwx

user:eg:rwx

group::r-x

mask::rwx

other::r-x

[root@station10 mnt]# cd dir/

[root@station10 dir]# mkdir dir1

[root@station10 dir]# getfacl dir1/

# file: dir1/

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

# 我们刚刚用 root 建的第一个文件夹( dir )我给它添加了第二个属主。现在需要再到 dir 目录下再建立一个文件夹( dir1 )并且也让它属于 eg 用户,可是建完之后它并不属于 eg ,而是单单属于 root 。那我又得给它增加第二属主太麻烦了。可以使用一种方法让它一直保持第一层的特性。如下所示:

[root@station10 mnt]# ls -ld dir/

drwxrwxr-x+ 3 root root 1024 6 月 4 22:27 dir/

[root@station10 dir]# ls -ld dir1/

drwxr-xr-x. 2 root root 1024 6 月 4 22:36 dir1/

看到 dir 与 dir1 的 ls -ld 有点不一样,那是因为 dir1 没有保持 dir 的特性( + )。那接下来我就让它保持 dir 的特性。

就是在建立文件夹的时候加上一个 d ,就可以让它里面建立的第二层第三层等等都保持第一层的特性。如下 :

[root@station10 mnt]# mkdir Docu

[root@station10 mnt]# setfacl -m d :u:eg:rwx Docu

[root@station10 mnt]# getfacl Docu/

# file: Docu/

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

default:user::rwx

default:user:eg:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

[root@station10 mnt]# cd Docu/

[root@station10 Docu]# mkdir Docu1

[root@station10 Docu]# getfacl Docu1/

# file: Docu1/

# owner: root

# group: root

user::rwx

user:eg:rwx

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:eg:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

# 观察到实验的结果了吧。

现在我想把第一层文件恢复原来的样子:

[root@station10 mnt]# setfacl -x d:u:eg Docu/ # ( -x :删除)恢复只有一个属主,还留有 defaults 。

[root@station10 mnt]# setfacl -b Docu/ # 恢复正常。可以直接使用 -b ( -b 级别高于 -x )。

s 位程序:可执行文件

文件被谁运行就归谁所有:

[root@station10 ~]# /bin/sleep 1000

[root@station10 ~]# ps -eo command,group,user | grep sleep | grep -v grep

/bin/sleep 1000 root root

[eg@station10 ~]$ /bin/sleep 1000

[eg@station10 ~]$ ps -eo command,group,user | grep sleep | grep -v grep

/bin/sleep 1000 eg eg

观察如上实验,就可发现不管是 root 还是 eg 运行 sleep ,它的属主都是运行者的。

在工业环境中,有时会要求我们用某个用户来运行某个程序,但是这个程序却不归我们这个用户所有。也就只有 S 位程序能够实现。

[root@station10 ~]# ls -l /bin/sleep

-rwxr-xr-x. 1 root root 27880 6 月 14 2010 /bin/sleep

[root@station10 ~]# chmod 4755 /bin/sleep

[root@station10 ~]# ls -l /bin/sleep


[eg@station10 ~]$ /bin/sleep 1000

[eg@station10 ~]$ ps -eo command,group,user | grep sleep | grep -v grep

/bin/sleep 1000 eg root

完全和刚刚的相反了,属主是 root ,而不是 eg 。(也可以是组)

s 位程序:目录

对于目录而言,研究 s 程序只研究组。

[root@station10 mnt]# mkdir dir

[root@station10 mnt]# chown wang5:eg dir/ #dir 属于 wang5 用户,属于 eg 组。

[root@station10 mnt]# chmod 2755 dir/

[root@station10 mnt]# ls -ld dir/

drwxr-sr-x. 2 wang5 eg 1024 6 月 4 23:40 dir/

[root@station10 mnt]# cd dir

[root@station10 dir]# mkdir d1 # 在 dir 里新建 d1

[root@station10 dir]# ls -ld d1/

drwxr-sr-x. 2 root eg 1024 6 月 4 23:40 d1/

root 建立的都必须归 eg 组。连 root 都必须尊守。

原理:新建内节点。

[root@station10 dir]# cp -rp /etc/ ./

[root@station10 dir]# ls -ld *

drwxr-sr-x. 2 root eg 1024 6 月 5 09:19 d1

drwxr-sr-x. 117 root root 8192 6 月 5 09:19 etc

漏洞:移动或拷贝文件,组就会归移动者。

Other t 位 (对文件的保护)

t 位 只对 777 目录,一般是 tmp 。

[root@station10 mnt]# mkdir tmp

[root@station10 mnt]# chmod 1777 tmp

[root@station10 mnt]# ls -ld tmp/


[root@station10 mnt]# cd tmp/

[root@station10 tmp]# touch 1.txt

[root@station10 tmp]# ls -l 1.txt

-rw-r--r--. 1 root root 0 Jun 6 21:55 1.txt

[root@station10 tmp]# su – wang5

[wang5@station10 ~]$ cd /mnt/tmp/

[wang5@station10 tmp]$ rm -rf 1.txt

rm: 无法删除 "1.txt": 不允许的操作

增加了 t 位,是对 777 目录的保护,只能是自己本身和 root 可以删除外其它用户不可删除。

REDHAT6

查看更多关于RHEL6上课笔记之acl的详细内容...

  阅读:34次