1.samba服务器的安装及访问调式
yum install samba-client.x86_64 samba-common.x86_64 samba.x86_64 -y
getenforce
enforcing ##selinux状态
setsebool -P samba_enable_home_dirs on
useradd -M -s /sbin/nologin bobo
smbpasswd -a bobo
pdbedit -L
smbclient -L //172.25.254.234 -U bobo
hostname
vim /etc/hosts
smbclient //172.25.254.234/HEHE -U bobo
***2.samba 共享目录***
mkdir /westos
chcon -t samba_share_t /westos/
vim /etc/samba/smb.conf ##samba 共享目录
[HEHE]
comment= /westos ##共享说明
path = /westos ##共享目录路径
systemctl restart smb.service
smbclient -L //172.25.254.234 -U student
smbclient //172.25.254.234/HEHE -U student
3.共享自创建目录和系统建立目录
共享目录自建立目录时需要修改selinux属性
mkdir /redhatlinux/
semanage fcontext -a -t samba_share_t '/redhatlinux(/.*)?'
restorecon -FvvR /redhatlinux/
vim /etc/samba/smb.conf
systemctl
共享系统建立的目录时需要修改selinux属性,此方式修改针对所有目录,一旦开放seliux不保护目录访问
setsebool -P samba_export_all_rw on ##可以读写
setsebool -P samba_export_all_ro on ##只读
修改配置文件,写入共享目录的信息
smbcilent //172.25.254.134/mnt -U student
4.限制挂载共享目录
mount //172.25.61.150/westos /mnt/ -o username=student,password=westos
默认可以直接挂载
vim /etc/samba/smb.conf
hosts allow = 172.25.61.150##白名单,231可以挂载,其他主机不行
hosts deny = 172.25.61.250 ##黑名单,231不可以挂载,其他主机可以
hosts deny = 172.25.61.231 172.25.61.131 ##多个黑名单
vim /etc/fstab
//172.25.61.150/westos /mnt cifs defaults,username=student,password=student 0 0##设置自动挂载
测试;
mount //172.25.254.231/westos /mnt/ -o username=student,password=westos
df
5.匿名用户访问
vim /etc/samba/smb.conf
123 security = user
124 passdb backend = tdbsam
125 map to guest = bad user
326 [mnt]
327 comment = mnt
328 path = /mnt
329 guest ok = yes
systemctl restart smb
mount //172.25.254.134/mnt /guazai/ -o username=guest ##把共享目录挂载到/guazai/目录下
6.samba共享目录的管理参数
vim /etc/samba/smb.conf
writeable = yes ##写权限打开
write list = student ##对student可写
write list = +student ##对student组可写
valid users = student ##student用户可以使用共享目录
valid users = @student ##student组的用户可以使用共享目录
browseable = no ## =no是隐藏共享目录
admin users = student ##使samba用户student拥有root权限
7.smb多用户挂载
在客户端
yum install cifs-utils.x86_64 -y
vim /root/passfile
username=bobo
passwd=redhat
chmod 600 /root/passfile
mount -o credentias=/root/passfile,multiuser,sec=ntlmssp //172.25.254.134/redhatlinu /mnt
su - student
cifscreds add -u bobo 172.25.254.134
touch file ##可以创建文件
su - test
cifscreds add -u bobo 172.25.254.134
ls ##不可以创建文件