如何实现SAMBA文件共享服务
今天小编给大家分享一下如何实现SAMBA文件共享服务的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
服务端操作:
1.关闭防火墙,关闭selunix
[root@hejie~]#setenforce0[root@hejie~]#systemctlstopfirewalld
2.安装软件包
[root@hejie~]#yuminstallsamba-*-y
3.启动smb服务并设置开机自启
[root@hejie~]#systemctlstartsmb[root@hejie~]#systemctlenablesmbCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/smb.serviceto/usr/lib/systemd/system/smb.service.
关于Samba的配置文件
[root@hejie~]#grep-Ev'^#|^$'/etc/samba/smb.conf[global]//全局参数workgroup=SAMBA//工作组名称非常重要security=user//安全验证方式,总共四种//share:无需验证身份,简单方便,安全性差//user:需要验证用户密码才可以访问,安全性高//server:需要通过三方服务器验证账号密码,(集中管理账户)//domain:使用域控制器进行身份验证passdbbackend=tdbsam//定义用户后台的类型,共有三种//smbpasswd:为系统用户设置Samba服务程序的密码//tdbsam:创建数据库文件并使用pdbedit命令建立Samba服务程序的用户//ldapsam:基于LDAP服务进行账户验证printing=cups//设置Samba共享打印机的类型printcapname=cups//设置共享打印机的配置文件loadprinters=yes//设置在Samba服务启动时是否共享打印机设备cupsoptions=raw//打印机的选项[homes]//共享参数comment=HomeDirectories//描述信息validusers=%S,%D%w%S//允许访问该共享的用户browseable=No//指定共享信息是否可见readonly=Noinheritacls=Yes[printers]comment=AllPrinters任意字符串path=/var/tmp共享目录路径printable=Yescreatemask=0600browseable=No指定该共享是否可以浏览[print$]comment=PrinterDriverspath=/var/lib/samba/driverswritelist=root允许写入该共享的用户createmask=0664directorymask=0775
4.添加用户”zhengran”,不创建家目录,并设置密码。
[root@hejie~]#useradd-Mzhengran[root@hejie~]#smbpasswd-azhengranNewSMBpassword:RetypenewSMBpassword:Addeduserzhengran.
假设这里映射”zhengran”用户为share用户,那么就要在/etc/samba/smbusers文件中添加如下内容:
[root@hejie~]#echo'zhengran=share'>/etc/samba/smbusers
5.在全局配置中添加如下内容:
[root@hejie~]#vim/etc/samba/smb.conf[global]workgroup=SAMBAsecurity=userusernamemap=/etc/samba/smbusers//添加此行内容passdbbackend=tdbsam
6.创建一个共享目录“zhengran”,并更改其属主属组为用户“zhengran”
[root@hejie~]#mkdir/opt/zhengran[root@hejie~]#chown-Rzhengran.zhengran/opt/zhengran/[root@hejie~]#ll/opt/total0drwxr-xr-x.2zhengranzhengran6Aug717:22zhengran
7.配置共享
[root@hejie~]#cat>>/etc/samba/smb.confcomment=zhengranwoaini//注释信息>path=/opt/zhengran//共享目录路径>browseable=yes//指定该共享是否可以浏览>guestok=yes//指定该共享是否允许guset账户访问>writable=yes//指定目录是否可写>writelist=share//允许写入该共享的用户,组要用@表示,例如:writelist=root,@root>public=yes//是否允许匿名访问>EOF
8.用testparm检查配置文件是否有语法错误,可显示最终生效的配置
[root@hejie~]#testparmLoadsmbconfigfilesfrom/etc/samba/smb.confrlimit_max:increasingrlimit_max(1024)tominimumWindowslimit(16384)Processingsection"[homes]"Processingsection"[printers]"Processingsection"[print$]"Processingsection"[zhengran]"LoadedservicesfileOK.Serverrole:ROLE_STANDALONEPressentertoseeadumpofyourservicedefinitions#Globalparameters[global]workgroup=SAMBAprintcapname=cupssecurity=USERusernamemap=/etc/samba/smbusersidmapconfig*:backend=tdbcupsoptions=raw[homes]comment=HomeDirectoriesbrowseable=Noinheritacls=Yesreadonly=Novalidusers=%S%D%w%S[printers]comment=AllPrinterspath=/var/tmpbrowseable=Noprintable=Yescreatemask=0600[print$]comment=PrinterDriverspath=/var/lib/samba/driverscreatemask=0664directorymask=0775writelist=root[zhengran]comment=zhengranwoainipath=/opt/zhengranguestok=Yesreadonly=Nowritelist=share
9.重启smb服务
[root@hejie~]#systemctlrestartsmb
客户端上操作:
1.安装工具包
[root@hyj~]#yuminstallsamba-clientcifs-utils-y
在客户机查看samba服务端有哪些共享资源
[root@hyj~]#smbclient-L192.168.56.11-UshareEnterSAMBA\share'spassword:SharenameTypeComment--------------------print$DiskPrinterDriverszhengranDiskzhengranwoainiIPC$IPCIPCService(Samba4.6.2)ReconnectingwithSMB1forworkgrouplisting.ServerComment----------------WorkgroupMaster----------------
3.创建目录,并将samba服务器的共享资源zhengran挂载到客户机本地
[root@hyj~]#mkdir/opt/ran[root@hyj~]#mount-tcifs//192.168.56.11/zhengran/opt/ran-ousername=share,password=123[root@hyj~]#df-hFilesystemSizeUsedAvailUse%Mountedon/dev/mapper/CentOS-root17G1016M16G6%/devtmpfs982M0982M0%/devtmpfs993M0993M0%/dev/shmtmpfs993M8.5M984M1%/runtmpfs993M0993M0%/sys/fs/cgroup/dev/sda11014M125M890M13%/boottmpfs199M0199M0%/run/user/0//192.168.56.11/zhengran47G5.4G42G12%/opt/ran
4.在客户机挂载点创建新文件
[root@hyj~]#cd/opt/ran/[root@hyjran]#touch123[root@hyjran]#ls123
5.在服务器上验证
[root@hejie~]#cd/opt/zhengran/[root@hejiezhengran]#ls123配置匿名共享
服务端
1.修改配置文件
[root@hejie~]#vim/etc/samba/smb.conf[global]workgroup=SAMBAsecurity=usermaptoguest=BadUser//添加此行
2.创建共享目录
[root@hejie~]#mkdir/opt/ranran[root@hejie~]#chmod777/opt/ranran/[root@hejie~]#ll/opt/ranran/-ddrwxrwxrwx.2rootroot6Aug719:24/opt/ranran/
3.配置共享
[root@hejie~]#cat>>/etc/samba/smb.confcomment=ranranwoaini>path=/opt/ranran>browseable=yes>writable=yes>guestok=yes>public=yes>EOF
4.重启服务
[root@hejie~]#systemctlrestartsmb
5.在客户机上查看服务器端有哪些共享资源
[root@hyj~]#smbclient-L192.168.56.11-U'BadUser'EnterSAMBA\BadUser'spassword://这里直接敲回车,不用输入密码SharenameTypeComment--------------------print$DiskPrinterDriverszhengranDiskzhengranwoainiranDiskranranwoainiIPC$IPCIPCService(Samba4.6.2)ReconnectingwithSMB1forworkgrouplisting.ServerComment----------------WorkgroupMaster----------------
6.将samba服务器的共享资源ran挂在到客户机上
[root@hyj~]#mount-tcifs//192.168.56.11/ran/opt/ran-ousername='BadUser'PasswordforBadUser@//192.168.56.11/ran:[root@hyj~]#df-hFilesystemSizeUsedAvailUse%Mountedon/dev/mapper/centos-root17G1016M16G6%/devtmpfs982M0982M0%/devtmpfs993M0993M0%/dev/shmtmpfs993M8.5M984M1%/runtmpfs993M0993M0%/sys/fs/cgroup/dev/sda11014M125M890M13%/boottmpfs199M0199M0%/run/user/0//192.168.56.11/ran47G5.4G42G12%/opt/ran
7.在客户机上进入共享目录创建新文件
[root@hyj~]#cd/opt/ran/[root@hyjran]#ls[root@hyjran]#touchabc[root@hyjran]#lsabc
8.在服务端验证
[root@hejie~]#cd/opt/ranran/[root@hejieranran]#lsabc
以上就是“如何实现SAMBA文件共享服务”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。