Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15317260
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2010-03-20 19:05:26

浅析rhel5.1如何配置selinux开启后的samba和nfs与windows文件共享

1.安装samba
[root@localhost samba]# rpm -ivh samba-3.0.25b-0.el5.4.i386.rpm
[root@localhost samba]# rpm -ivh samba-client-3.0.25b-0.el5.4.i386.rpm
[root@localhost samba]# rpm -ivh samba-common-3.0.25b-0.el5.4.i386.rpm
[root@localhost samba]# rpm -ivh system-config-samba-1.2.39-1.el5.noarch.rpm

2.创建系统用户和自定义用户组
[root@localhost ~]# useradd gliethttp
将自动创建/home/gliethttp目录,如果没有创建,请自行创建
[root@localhost ~]# passwd gliethttp
[root@localhost ~]# ls -l /home/
total 56
drwx------ 2 gliethttp  gliethttp  4096 Mar 20 15:34 gliethttp
drwx------ 2 test test 4096 Mar 29  2007 test
[root@localhost ~]# groupadd gliethttp123 创建用户组gliethttp123
[root@localhost ~]# usermod -g gliethttp123 gliethttp  将用户gliethttp的组改为gliethttp123

3.创建组内成员共享目录
[root@localhost ~]# mkdir -p /vobs/samba_shares
[root@localhost ~]# chown :gliethttp123 /vobs/samba_shares
[root@localhost ~]# chmod 770 /vobs/samba_shares
[root@localhost ~]# chcon -t samba_share_t /vobs/samba_shares 如果是直接共享或者符号链接到nfs目录,那么父目录vobs就不用改变-t为samba_share_t,如果是符号链接的话,那么所有父目录都需要设置为samba_share_t属性.[luther.gliethttp]

4.为samba添加用户密码
[root@localhost ~]# smbpasswd -a gliethttp
[root@localhost ~]# smbpasswd -x gliethttp 用来删除samba用户密码

5.为selinux设置samba特有文件属性,使能samba对nfs的访问权限(但是samba和nfs互访速度奇慢,后来发现mount -t nfs -o nolock可以解决这个问题,如果nfs和samba之间不能拖动复制,可以使用ctrl+c 和ctrl+v组合)
[root@localhost ~]# chcon -t samba_etc_t /etc/samba/smb.conf /etc/samba/passdb.tdb
[root@localhost ~]# ls -Z /etc/samba/ 只需要下面3个文件就可以正常使用samba了
-rw-------  root root root:object_r:samba_etc_t        passdb.tdb
-rw-------  root root system_u:object_r:samba_secrets_t secrets.tdb
-rw-r--r--  root root root:object_r:etc_t              smb.conf

[root@localhost ~]# chcon -t samba_share_t /vobs/samba_shares

[root@localhost ~]# getsebool -a|grep samba
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_share_nfs --> off
use_samba_home_dirs --> off
[root@localhost ~]# setsebool samba_enable_home_dirs on
[root@localhost ~]# setsebool samba_share_nfs on

6.配置smb.conf文件
[root@localhost ~]# vim /etc/samba/smb.conf
[global]
; 下面的3行网上说可以用来解决samba和nfs互访速度奇慢问题,但是并不奏效,后来发现mount -t nfs -o nolock可以解决这个问题,如果nfs和samba之间不能拖动复制,可以使用ctrl+c 和ctrl+v组合
;    strict locking = no
;    posix locking =no
;    kernel oplocks = no
# 在末尾追加如下共享目录即可
# 如果不希望输入用户名密码登陆,可以将[global]区
# 中的security = user
# 改为security = share即可
[shares]
    comment = 数据交换公共目录
    path = /vobs/samba_shares
    guest ok = yes
    writable = yes
;   valid users = @gliethttp123

7.重启samba服务
[root@localhost ~]# service smb restart
或者
[root@localhost ~]# /etc/rc.d/init.d/smb restart

我们不能直接重定向/home/gliethttp用户目录,但是我们可以在/home/gliethttp用户目录下建立指向其他大存储容量的分区或者网盘,然后清除/home/gliethttp目录下写权限,只开启符号链接文件的写权限,以保证/home所在分区不至于用户文件太大太多而出现磁盘full现象.
如果是直接共享或者符号链接到nfs目录,那么父目录vobs就不用改变-t为samba_share_t,如果是符号链接的话,那么所有父目录都需要设置为samba_share_t属性.[luther.gliethttp]
[root@localhost ~]# chmod a-w /home/gliethttp
[root@localhost ~]# chcon -t samba_share_t /vobs
[root@localhost ~]# chcon -t samba_share_t /vobs/home_users
[root@localhost ~]# mkdir -p /vobs/home_users/gliethttp
[root@localhost ~]# chown gliethttp:gliethttp /vobs/home_users/gliethttp
[root@localhost ~]# ls -Z /vobs/home_users/
drwxr-xr-x  gliethttp  gliethttp  root:object_r:samba_share_t      gliethttp
[root@localhost ~]# ln -s /vobs/home_users/gliethttp /home/gliethttp/vobs
[root@localhost ~]# mount -t nfs -o nolock 10.1.0.1:/vobs/movie /mnt/movie_nfs
[root@localhost ~]# ln -s /mnt/movie_nfs /home/gliethttp/movie 这里的mnt作为nfs的父目录,不需要samba_share_t设置,如果nfs和samba之间不能拖动复制,可以使用ctrl+c 和ctrl+v组合

小结:最后就可以在windows下使用用户名gliethttp和密码登陆samba了



自动添加用户的脚本,直接更改用户目录
#!/bin/sh
useradd -d /vobs/home_users/"$1" -g gliethttp123 "$1"
ln -s /vobs/home_users/"$1" /home/"$1"
smbpasswd -a "$1"
passwd "$1"
另外在每个用户目录/vobs/home_users/"$1"下建立.profile文件,这样当用户远程登录时将首先执行.profile,内核可以和.bashrc一样,比如

# .bashrc
# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

export PATH=/sbin:/usr/bin:$PATH
# Source global definitions

if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
export SVN_EDITOR=vim



以下横线代码作废
#!/bin/sh
useradd "$1"
usermod -g gliethttp123 "$1"
chmod a-w /home/"$1"
chown :gliethttp123 /home/"$1"
mkdir /vobs/home_users/"$1"
chown "$1":gliethttp123 /vobs/home_users/"$1"
ln -s /vobs/home_users/"$1" /home/"$1"/vobs
smbpasswd -a "$1"
passwd "$1"

PS:清楚window共享登陆用户名和密码
1. 控制面板==>用户账户==>选择账户,比如Administrator==>左上角的管理我的网络密码==>删除存储用户名和密码即可
2. 开始==>运行==>cmd
  cmd: net use
  cmd: net use \\192.168.1.101\tupian /del

文件:rhel5.1上的配置文件 - smb.conf.rar
大小:3KB
下载:下载


阅读(2034) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~