samba

1.samba服务器的安装及访问调试

yum install samba-client samba-common samba -y
systemctl stop firewalld
getsebool -a | grep samba
setsebool -P samba_enable_home_dirs on
smbpasswd -a student ##student必须是本机用户
pdbedit -L ##查看
pdbedit -x student ##删除

useradd westos -s /sbin/nologin -M
-s /sbin/nologin ##禁止交互式登陆
-M ##不建立家目录

测试:
smbclient -L //172.25.254.132 -U student ##用student身份登陆
smbclient //172.25.254.132/student -U student ##用student身份查看自己的目录

2.samba共享目录

vim /etc/samba/smb.conf
321         [共享名称]
322         comment = 共享说明
323         path = 共享目录路径

:wq

在这里插入图片描述

systemctl restart smb

共享目录自建立目录时需要修改的selinux属性,此方式修改只针对修改目录

semanage fcontext -a -t samba_share_t '/redhat(/.*)?'
restorecon -FvvR /redhat/

在这里插入图片描述
共享目录建立目录时需要修改的selinux属性,此方式修改针对所有目录,一旦开放,selinux不保护目录访问

setsebool -P samba_export_all_rw on		##可以读写
setsebool -P samba_export_all_ro on		##只读

测试:
smbclient //172.25.254.132/redhat -U student
在这里插入图片描述

semanage fcontext -a -t samba_share_t '/redhat(/.*)?'
restorecon -RvvF /redhat/

在这里插入图片描述

smbclient //172.25.254.132/redhat -U student

在这里插入图片描述

smbclient //172.25.254.132/redhat -U student

在这里插入图片描述
在这里插入图片描述

setsebool -P samba_export_all_ro on

在这里插入图片描述

3.共享限制

vim /etc/fstab
//172.25.254.132/redhat /mnt    cifs    defaults,username=student,password=westos       0 0

在这里插入图片描述

mount //172.25.254.132/redhat -o username=student,password=westos
df
//172.25.254.132/redhat  10473900 3519004   6954896  34% /mnt

在这里插入图片描述
白名单

vim /etc/samba/smb.conf
322         comment = /redhat
323         path = /redhat
324         hosts allow = 172.25.254.132
systemctl restart smb.service

在这里插入图片描述
132主机

mount //172.25.254.132/redhat -o username=student,password=westos
df
//172.25.254.132/redhat  10473900 3519004   6954896  34% /mnt

在这里插入图片描述
32主机

vim /etc/fstab
//172.25.254.132/redhat /mnt    cifs    defaults,username=student,password=westos       0 0
mount //172.25.254.132/redhat -o username=student,password=westos
mount: //172.25.254.132/redhat is write-protected, mounting read-only
mount: cannot mount //172.25.254.132/redhat read-only

在这里插入图片描述
黑名单:

vim /etc/samba/smb.conf
322         comment = /redhat
323         path = /redhat
324         hosts deny = 172.25.254.132
systemctl restart smb.service

在这里插入图片描述
132主机

mount //172.25.254.132/redhat -o username=student,password=westos
mount: //172.25.254.132/redhat is write-protected, mounting read-only
mount: cannot mount //172.25.254.132/redhat read-only

在这里插入图片描述
32主机

mount //172.25.254.132/redhat -o username=student,password=westos
df
//172.25.254.132/redhat  10473900  3519968   6953932  34% /mnt

在这里插入图片描述

4.samba匿名访问

vim /etc/samba/sam.conf
123         security = user
124         passdb backend = tdbsam
125         map to guest = bad user

321         [redhat]
322         comment = /redhat
323         path = /redhat
324         guest ok = yes

在这里插入图片描述
在这里插入图片描述

测试:

mount //172.25.254.132/redhat /mnt -o username=guest
df
//172.25.254.132/redhat  10473900 3540632   6933268  34% /mnt

在这里插入图片描述

5.samba 共享目录的管理参数

vim /etc/samba/smb.conf

321         [redhat]
322         comment = /redhat
323         path = /redhat
324         guest ok = yes
writable = yes	##打开写权限
write list = student	##可写列表:对student可写
write list = @redhat		##redhat组可写
valid users = student	##student可以使用共享目录
valid users = +redhat	##redhat组可以使用共享目录
browseable = no		##= no隐藏共享目录 =yes 不隐藏
admin user = student	##为共享目录添加管理员

测试:

1.writable

321         [redhat]
322         comment = /redhat
323         path = /redhat
324         writable = yes

在这里插入图片描述

mount //172.25.254.132/redhat /mnt -o username=student,password=westos
touch /mnt/file

在这里插入图片描述
无法写入,可能是权限的问题

umount /mnt/
chmod 777 /redhat/

在这里插入图片描述
再次尝试
在这里插入图片描述
注意此时selinux布尔值:
在这里插入图片描述
文件的安全上下文:
在这里插入图片描述
如果是默认的安全上下文:

在这里插入图片描述
再次测试:
在这里插入图片描述
需要修改布尔值:
在这里插入图片描述
再次测试:
在这里插入图片描述
所建立的文件所有人和所有组都是student

2.write list

321         [redhat]
322         comment = /redhat
323         path = /redhat
324 ;       writable = yes
325         write list = student

在这里插入图片描述
使用redhat 登陆

mount //172.25.254.132/redhat /mnt -o username=redhat,password=redhat
touch /mnt/file2

在这里插入图片描述
使用student用户

mount //172.25.254.132/redhat /mnt -o username=student,password=westos
touch /mnt/file1

在这里插入图片描述
将write list设置为组

vim /etc/samba/smb.conf
321         [redhat]
322         comment = /redhat
323         path = /redhat
324 ;       writable = yes
325         write list = +redhat

systemctl restart smb.service

在这里插入图片描述
使用redhat用户登陆

mount //172.25.254.132/redhat /mnt -o username=redhat,password=redhat
touch /mnt/file3

在这里插入图片描述
使用student用户
在这里插入图片描述
为student添加redhat组

usermod -G redhat student
mount //172.25.254.132/redhat /mnt -o username=student,password=westos
touch /mnt/file4

在这里插入图片描述

3.valid users

vim /etc/samba/smb.conf
321         [redhat]
322         comment = /redhat
323         path = /redhat
324 ;       writable = yes
325         write list = +redhat
326         valid users = redhat
systemctl restart smb.service

在这里插入图片描述
使用student登陆

mount //172.25.254.132/redhat /mnt -o username=student,password=westos

在这里插入图片描述
使用redhat登陆

mount //172.25.254.132/redhat /mnt -o username=redhat,password=redhat

在这里插入图片描述
设置为redhat组

vim /etc/samba/smb.conf 
321         [redhat]
322         comment = /redhat
323         path = /redhat
324 ;       writable = yes
325 ;       write list = +redhat
326         valid users = @redhat
systemctl restart smb.service

在这里插入图片描述
为student添加redhat组后再次使用student用户挂载

usermod -G redhat student
mount //172.25.254.132/redhat /mnt -o username=student,password=westos

在这里插入图片描述

4.browseable

vim /etc/samba/smb.conf
321         [redhat]
322         comment = /redhat
323         path = /redhat
324 ;       writable = yes
325 ;       write list = +redhat
326 ;       valid users = @redhat
327         browseable = no
systemctl restart smb.service

在这里插入图片描述

smbclient -L //172.25.254.132 -U redhat		##查看共享目录

在这里插入图片描述
共享的redhat被隐藏

5.admin user

321         [redhat]
322         comment = /redhat
323         path = /redhat
324 ;       writable = yes
325 ;       write list = +redhat
326 ;       valid users = @redhat
327 ;       browseable = no
328         admin users = redhat

在这里插入图片描述

mount //172.25.254.132/redhat /mnt -o username=student,password=westos
touch /mnt/test1
mount //172.25.254.132/redhat /mnt -o username=redhat,password=redhat
touch /mnt/test2
ls /mnt

在这里插入图片描述

6.多用户挂载

设置多用户挂载前,root用户的挂载任意普通用户也可以查看:
在这里插入图片描述

客户端root用户:

yum install cifs-utils.x86_64 -y

vim /root/passfile		##写入samba服务端的用户和密码

username=student
password=westos

在这里插入图片描述

chmod 600 /root/passfile
mount -o credentials=/root/smbpass,multiuser,sec=ntlmssp //172.25.254.133/redhat /mnt
su - test
ls /mnt

在这里插入图片描述
redhat用户

cifscreds add -u student 172.25.254.133 		##与客户端超级用户挂载时的smb用户相同,挂载成功

在这里插入图片描述
如果使用不同的用户或者密码错误,挂载依然被拒绝

ls: cannot access /mnt: Permission denied
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值