您的位置:首页 > 其它

RH413企业安全加固 第7章 管理附加文件权限

2016-01-18 23:00 344 查看
第7章管理附加文件权限(注意:红字)

1、umask

1) 登录用户su

用来配置环境变量,用户的权限。

2) 非登录用户su

用来执行脚本的。

Umask文件是用来指定默认的权限是什么,和你默认用户创建的权限是什么。

3) /etc/profile是系统的全局变量文件

if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then

umask 002

else

umask 022

fi

先判断UID是否小于199与判断id -gn (gid)和id -un (uid)是否相等

[student@student root]$ id -gn

student

[student@student root]$ id -un

Student

这个判断如果同时满足的情况给予002的权限,否则为022的权限

临时更改umask值的命令为:umask 022

4) /etc/bashrc 是个性化设置

个性化例子:

[student@student root]$ alias

alias l.='ls -d .* --color=auto'

alias ll='ls -l --color=auto'

alias ls='ls --color=auto'

alias vi='vim'

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

5) ./bashrc 和 ./bash_profile是存放用户的配置

6) ./bash_logout是用户退出前要做什么事

7) 配置文件加载顺序先加载:

/etc/profile--->/etc/profile.d/*---->~/.bash_profile---->~/.bashrc-->/etc/bashrc

-->~/.bash_logout

[root@student ~]#echo 'echo /etc/profile 1' >> /etc/profile

[root@student ~]#echo 'echo .bash_profile 2' >> .bash_profile

[root@student ~]#echo 'echo .bashrc 3' >> .bashrc

[root@student ~]#echo 'echo /etc/bashrc 4 ' >> /etc/bashrc

Last login: Mon Jan 18 16:12:06 2016 from 10.10.10.1

/etc/profile 1

.bash_profile 2

.bashrc 3

/etc/bashrc 4

以上就是用户登录时执行的配置文件

8) 更改student用户的umask权限

echo 'umask 0427' >> ~student/.bashrc

[student@student ~]$ su root

Password:

[root@student student]# su student

[student@student ~]$ umask

0427

2、ACL是针对某一个文件或某一个目录设置值,使用ACL必须开启文件系统支持

[root@student ~]# tune2fs -l /dev/mapper/sdd5

tune2fs 1.41.12 (17-May-2010)

Filesystem volume name: <none>

Last mounted on: /mnt

Filesystem UUID: 62ad34c8-d172-4fce-8664-c56db3b4d6ac

Filesystem magic number: 0xEF53

Filesystem revision #: 1 (dynamic)

Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize

Filesystem flags: signed_directory_hash

Default mount options: (none)

[root@student ~]# tune2fs -o acl /dev/mapper/sdd5

tune2fs 1.41.12 (17-May-2010)

[root@student ~]# tune2fs -l /dev/mapper/sdd5

tune2fs 1.41.12 (17-May-2010)

Filesystem volume name: <none>

Last mounted on: /mnt

Filesystem UUID: 62ad34c8-d172-4fce-8664-c56db3b4d6ac

Filesystem magic number: 0xEF53

Filesystem revision #: 1 (dynamic)

Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize

Filesystem flags: signed_directory_hash

Default mount options: acl

[root@student ~]# ls -ld /test/

drwxr-sr-x. 2 root student 4096 Jan 18 17:08 /test/

1)查看acl设置

[root@student ~]# getfacl /test/

getfacl: Removing leading '/' from absolute path names

# file: test/

# owner: root

# group: student

# flags: -s-

user::rwx

group::r-x

other::r-x

2)不设置默认权限

[root@student ~]# setfacl -m u:student:rw /test/

[root@student ~]# getfacl /test/

getfacl: Removing leading '/' from absolute path names

# file: test/

# owner: root

# group: student

# flags: -s-

user::rwx

user:student:rw-

group::r-x

mask::rwx

other::r-x

3)设置默认权限

[root@student ~]# setfacl -m d:u:student:rw /test

[root@student ~]# getfacl /test/

getfacl: Removing leading '/' from absolute path names

# file: test/

# owner: root

# group: student

# flags: -s-

user::rwx

user:student:rw-

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:student:rw-

default:group::r-x

default:mask::rwx

default:other::r-x

[root@student ~]# su - student

[student@student ~]$ cd /test/

-bash: cd: /test/: Permission denied

只要默认用户权限下没有执行权限的情况,student用户就不能进入此目录也没有办法写。

如果不设置默认用户权限的话,使用root用户在/test/目录下在创建目录也是无法进入和没有办法写的。

4)取消acl权限

[root@student student]# setfacl -x u:student /test/

5)设置默认权限

[root@student student]# setfacl -m u:student:rwx /test/

[root@student student]# setfacl -m d:u:student:rwx /test/

[root@student student]# setfacl -m m:rw /test/

[root@student student]# getfacl /test/

getfacl: Removing leading '/' from absolute path names

# file: test/

# owner: root

# group: student

# flags: -s-

user::rwx

user:student:rwx #effective:rw-

group::r-x #effective:r--

mask::rw-

other::r-x

default:user::rwx

default:user:student:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

[root@student student]# su student

[student@student ~]$ cd /test/

bash: cd: /test/: Permission denied
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: