当前位置: 代码迷 >> 综合 >> samba 文件共享
  详细解决方案

samba 文件共享

热度:22   发布时间:2023-12-15 23:16:47.0

##5.samba

基于SMB协议并由服务端和客户端组成的开源文件共享软件,实现了linux和windows之间的文件共享

[root@desktop yum.repos.d]# yum install samba samba-common samba-client -y    ##安装samba及其从属文件

[root@desktop yum.repos.d]# systemctl start smb

[root@desktop yum.repos.d]# firewall-cmd --permanent --add-service=samba ##配置火墙策略
success
[root@desktop yum.repos.d]# firewall-cmd --reload

success


指定工作组名称

[root@desktop yum.repos.d]# vim /etc/samba/smb.conf            

 89         workgroup = WESTOS                                   ##指定工作组名称
 90         server string = Samba Server Version %v         ##服务器介绍信息,参数%v为显示samba版本
 91

 92 ;       netbios name = MYSERVER


 访问黑白名单
 94 ;       interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
 95 ;       hosts allow = 172.25.254.44
 96         hosts deny=172.25.254.44
测试:

smbclient -L //172.25.254.144



##samba用户的建立和删除

[root@desktop yum.repos.d]# id westos

uid=1001(westos) gid=1001(westos) groups=1001(westos)[root@desktop yum.repos.d]

# smbpasswd -a student            ##建立samba用户,此用户必须是系统中存在的用户

New SMB password:

Retype new SMB password:

[root@desktop yum.repos.d]# smbpasswd -a westos

New SMB password:

Retype new SMB password:

[root@desktop yum.repos.d]# pdbedit -L                        ##列出用户列表student:1000:Student User

westos:1001:

admin:1002:

[root@desktop yum.repos.d]# pdbedit -x admin   ##删除samba用户admin

[root@desktop yum.repos.d]# pdbedit -L

student:1000:Student User

westos:1001:


[root@desktop yum.repos.d]# vim /etc/samba/smb.conf

[root@desktop yum.repos.d]# setsebool -P samba_enable_home_dirs on      ## 设置访问samba家目录的布尔值

测试:使用学生用户登陆

smbclient //172.25.254.144/student -U student


yum install cifs-utils -y

mount //172.25.254.144/student /mnt/ -o username=westos,passwd=123  ##将westos用户家目录挂载到/mnt'下





添加公共文件/linux
   mkdir /westos/
   chmod 777 /westos/
 

   vim /etc/samba/smb.conf

        [linux]                                              ##共享文件名称
        comment = DATA directory             ##共享文件注释
        path = /westos                                           ##共享文件存放目录
        writable =yes                                                         ##是否可写

  systemctl restart smb

  设置安全上下文

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

 测试(客户端):

 smbclient  //172.25.254.100/linux -U student


mount //172.25.254.110/linux /mnt -o username=student,passwd=123

cd /mnt/

touch file2

ls   -l



其他参数:
;       write list = +student                                              ##可写用户组  同@student
        browseable = no                                                    ##是否显示本共享目录
;       valid users = @student                                           ##当前共享的有效用户组为student组 
        admin users = westos                                                ##共享的超级用户指定,(表示拥有这个身份,但不一定有超级用户的权力)


匿名用户:
vim /etc/samba/smb.conf

map to guest = bad user                         ##映射访客为匿名用户
guest ok = yes                                           ##是否所有人可见
测试:

mount -o username=guest,passwd="" //172.25.254.144/linux /mnt/




#多用户登陆
在客户端:
yum install samba-client.x86_64 -y
 vim /root/smbfile

cat /root/smbfile

username=westos
passwd=westos

chmod 600   /root/smbfile


mount -o credentials=/root/smbfile,sec=ntlmssp,multiuser //172.25.254.110 /linux /mnt/

[root@localhost mnt]# su - student
[student@localhost ~]$ cd /mnt
[student@localhost mnt]$ ls
ls: reading directory .: Permission denied
[student@localhost mnt]$ cifscreds add -u student 172.25.254.110    ##获取服务端用户权限
Password:


设置开机自动挂载

vim /etc/fstab

//172.25.254.110/linux    /mnt   cifs   defaults,username=guest,passwd=""  0  0 


  相关解决方案