selinux基本配置+nis简介及挂载
SELINUX
DAC 自主安全控制 -rw-r--r-- root root f1
mac 强制安全控制 安全上下文 (五个字段)
所有者:角色:type
[[email protected] ~]#setup //启用selinux,然后要重启电脑
[[email protected] ~]# ll -Z //查看安全上下文
-rw------- root root system_u:object_r:user_home_t anaconda-ks.cfg
[[email protected] ~]# ps auxZ |less
[[email protected] ~]# getenforce //查看状态
Enforcing //强制安全机制
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive //警告安全机制
实验环境:开启了selinux强制安全机制
案例一
1.安装httpd服务
2.默认目录时能正常启动,修改主目录后不能正常启动
vim /etc/httpd/conf/httpd.conf
文件内容修改:
281 DocumentRoot "/webroot"
[[email protected] html]# service httpd restart
停止 httpd: [确定]
启动 httpd:Syntax error on line 281 of
/etc/httpd/conf/httpd.conf:
DocumentRoot must be a directory [失败] ////重启失败
3.查看安全上下文:
[[email protected] html]# ll -Z /webroot/
-rw-r--r-- root root root:object_r:default_t index.html
[[email protected] html]# ps auxZ |grep http
[[email protected] html]# ll -Z /var/www/html/
-rw-r--r-- root root root:object_r:httpd_sys_content_t index.html
4.进程类与对象一致,才能够管辖,类是强制的必须是一致
[[email protected] html]# chcon -R -t httpd_sys_content_t /webroot //改变安全上下文
[[email protected] html]# setenforce 1
[[email protected] html]# service httpd restart
停止 httpd: [确定]
启动 httpd: [确定] //重启成功
[[email protected] ~]# sealert -b //查看图形界面下的错误信息
5.改变selinux设置的方法:
vim /etc/sysconfig/selinux
system-config-selinux
system-config-securitylevel
setenforce 1 |0
semange
semanage fcontext -l |grep http //查看selinux和http相关的安全策略库
semanage port -l |grep httpd //查看安全策略下http支持的端口
semanage port -a -t http_port_t -p tcp 800 //增加支持的非标准端口
6.想关闭打开策略,所以库内设置多个开关(se库)
增加支持的非标准端口
[[email protected] ~]# getsebool -a //查看开关
[[email protected] ~]# setsebool -P ftp_home_dir=1 //打开开关
案例二
1.安装samaba
[[email protected] Server]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm
[[email protected] Server]# rpm -ivh samba-3.0.33-3.7.el5.i386.rpm
[[email protected] Server]# service smb start
2.配置共享
vim /etc/samba/smb.conf
282 [smbuser1]
283 comment = Public Stuff
284 path = /tmp/user1
285 public = yes
[qq]
path = /abc
public = yes
[[email protected] Server]# mkdir /tmp/user1
[[email protected] Server]# mkdir /abc
[[email protected] Server]# useradd user1
[[email protected] Server]# passwd user1
[[email protected] Server]# chown user1.user1 /tmp/user1/
[[email protected] Server]# service smb restart
[[email protected] Server]# smbpasswd -a user1
客户端访问
服务器测试:
[[email protected] ~]# tail -f /var/log/messages
ug 21 17:53:29 localhost smbd[3918]: '/abc' does not exist or permission denied when connecting to [qq] Error was 权限不够
[[email protected] Server]# chcon -t samba_share_t /abc
客户端访问
测试结果:可以访问qq文件,不可以访问家目录
为了客户端可以访问到家目录:
服务器端:
[[email protected] ~]# tail -f /var/log/messages
run sealert -l d97cd8c2-37b4-44e0-8b85-941547a1d8a6
[[email protected] Server]# sealert -l d97cd8c2-37b4-44e0-8b85-941547a1d8a6
以下命令将允许这个权限:
setsebool -P samba_enable_home_dirs=1
[[email protected] Server]# setsebool -P samba_enable_home_dirs=1
测试结果:可以进入家目录
NIS (网络信息系统、身份验证、集中管理帐号)
工作方式:基于rpc
rpc: portmap 分配定位客户端端口
拓扑图:
[[email protected] ~]# rpcinfo –p //查看rpc进程,默认正常运行
服务器配置
1.安装ypcbind和ypcserv
[[email protected] Server]# rpm -ivh ypserv-2.19-5.el5.i386.rpm
[[email protected] Server]# chkconfig --list |grep yp
[[email protected] Server]# service ypserv start
[[email protected] Server]# chkconfig ypserv on
[[email protected] Server]# service yppasswdd start
[[email protected] Server]# chkconfig yppasswdd on
2.产生账户库
[[email protected] Server]# cd /var/yp
[[email protected] yp]# ll
-rw-r--r-- 1 root root 16669 2008-08-11 Makefile //决定导入文件
vim Makefile
117 all: passwd group hosts \
vim /etc/sysconfig/network
文件内容增加:
NISDOMAIN=rhce //定义域,域名rhce
重启电脑
/usr/lib/yp/ypinit -m //导入资料库
list, type a <control D>.
Is this correct? [y/n: y] y
查看:
[[email protected] ~]# cd /var/yp/rhce/
[[email protected] rhce]# ll //查看导入的文件
客户端配置
1.[[email protected] ~]# rpm -qa |grep yp
ypbind-1.19-11.el5
2.通过nis访问
setup
设置为nis验证(默认为本地帐号验证)
如图
设置域名和nis服务器
3.如果服务器创建新账户,不需要重新导入
[[email protected] ~]# cd /var/yp
[[email protected] yp]# make //更新资料库
挂载服务器home到客户端上
服务器端
vim /etc/exports
文件内容:
/nishome 192.168.2.0/24(rw,sync)
[[email protected] ~]# service nfs start
[[email protected] ~]# chkconfig nfs on
[[email protected] ~]# exportfs -rv
客户端
[[email protected] ~]# showmount -e 192.168.2.100 //查看是否能挂载
[[email protected] ~]# mount 192.168.2.100:/home /home
[[email protected] ~]# mount
192.168.2.100:/home on /home type nfs (rw,addr=192.168.2.100)
登录测试:
重新登录
自动挂载
服务器:
[[email protected] ~]# mkdir /nhome
[[email protected] ~]# useradd -d /nhome/user5 user5
[[email protected] ~]# passwd user5
[[email protected] ~]# cd /var/yp
[[email protected] yp]# make
vim /etc/exports
/nhome 192.168.2.0/24(rw,sync)
[[email protected] yp]# exportfs -rv
[[email protected] ~]# service ypserv restart (必须)
[[email protected] yp]# service yppasswdd restart(可选)
[[email protected] ~]# service nfs restart(必须)
客户端
umount /home
[[email protected] ~]# mkdir /nhome
vim /etc/auto.master
文件内容修改:
/nhome /etc/auto.qq --timeout=60
[[email protected] ~]# cp /etc/auto.misc /etc/auto.qq
vim /etc/auto.qq
文件内容加入:
* (注意这里的“-”)-ro,soft,intr 192.168.2.100:/nhome/&
[[email protected] ~]# chmod o+wt /nhome (可选)
[[email protected] ~]# service autofs restart (重启权限会消失)
登录测试
转载于:https://blog.51cto.com/yz406/999232