博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
搭建samba服务,实现局域网文件共享
阅读量:4967 次
发布时间:2019-06-12

本文共 8432 字,大约阅读时间需要 28 分钟。

#查看防火墙和selinux是否关闭,没有关闭要关闭。

[root@weblamp ~]# iptables -nL

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)

target prot opt source destination

Chain OUTPUT (policy ACCEPT)

target prot opt source destination
[root@weblamp ~]# getenforce
Disabled

#安装smaba

yum install samba samba-client samba-swat -y

#查看安装的包

[root@weblamp ~]# rpm -qa|grep samba
samba-winbind-3.6.23-45.el6_9.x86_64
samba-winbind-clients-3.6.23-45.el6_9.x86_64
samba-client-3.6.23-45.el6_9.x86_64
samba-3.6.23-45.el6_9.x86_64
samba-common-3.6.23-45.el6_9.x86_64
samba-swat-3.6.23-45.el6_9.x86_64

#启动并查看samba运行状态

[root@weblamp ~]# service smb start
Starting SMB services: [ OK ]
[root@weblamp ~]# service smb status
smbd (pid 5349) is running...

#重新加载(如果修改了配置文件)

[root@weblamp ~]#service smb reload

#新建文件夹

[root@weblamp ~]# mkdir /company -p
[root@weblamp ~]# cd /company/
[root@weblamp company]# ll
total 0
[root@weblamp company]# mkdir DSCS FLCG FM GYL HR KA SHARE TS WPCG ZMCS
[root@weblamp company]# ll
total 40
drwxr-xr-x 2 root root 4096 Dec 21 14:45 DSCS
drwxr-xr-x 2 root root 4096 Dec 21 14:45 FLCG
drwxr-xr-x 2 root root 4096 Dec 21 14:45 FM
drwxr-xr-x 2 root root 4096 Dec 21 14:45 GYL
drwxr-xr-x 2 root root 4096 Dec 21 14:45 HR
drwxr-xr-x 2 root root 4096 Dec 21 14:45 KA
drwxr-xr-x 2 root root 4096 Dec 21 14:45 SHARE
drwxr-xr-x 2 root root 4096 Dec 21 14:45 TS
drwxr-xr-x 2 root root 4096 Dec 21 14:45 WPCG
drwxr-xr-x 2 root root 4096 Dec 21 14:45 ZMCS

#创建共享目录

[root@weblamp company]# cd SHARE/
[root@weblamp SHARE]# ll
total 0
[root@weblamp SHARE]# mkdir DSCS FLCG FM GYL HR KA TOOLS TS WPCG ZMCS
[root@weblamp SHARE]# ll
total 40
drwxr-xr-x 2 root root 4096 Dec 21 15:15 DSCS
drwxr-xr-x 2 root root 4096 Dec 21 15:15 FLCG
drwxr-xr-x 2 root root 4096 Dec 21 15:15 FM
drwxr-xr-x 2 root root 4096 Dec 21 15:15 GYL
drwxr-xr-x 2 root root 4096 Dec 21 15:15 HR
drwxr-xr-x 2 root root 4096 Dec 21 15:15 KA
drwxr-xr-x 2 root root 4096 Dec 21 15:15 TOOLS
drwxr-xr-x 2 root root 4096 Dec 21 15:15 TS
drwxr-xr-x 2 root root 4096 Dec 21 15:15 WPCG
drwxr-xr-x 2 root root 4096 Dec 21 15:15 ZMCS
[root@weblamp SHARE]# cd ..

#创建用户

[root@weblamp company]# useradd -s /sbin/nologin zmcsadmin
[root@weblamp company]# useradd -g zmcsadmin -s /sbin/nologin zmcsuser
[root@weblamp company]# useradd -s /sbin/nologin hradmin
[root@weblamp company]# useradd -g hradmin -s /sbin/nologin hruser
[root@weblamp company]# useradd -s /sbin/nologin fmadmin
[root@weblamp company]# useradd -g fmadmin -s /sbin/nologin fmuser
[root@weblamp company]# useradd -s /sbin/nologin dscsadmin
[root@weblamp company]# useradd -g dscsadmin -s /sbin/nologin dscsuser
[root@weblamp company]# useradd -s /sbin/nologin tsadmin
[root@weblamp company]# useradd -g tsadmin -s /sbin/nologin tsuser
[root@weblamp company]# useradd -s /sbin/nologin flcgadmin
[root@weblamp company]# useradd -g flcgadmin -s /sbin/nologin flcguser
[root@weblamp company]# useradd -s /sbin/nologin kaadmin
[root@weblamp company]# useradd -g kaadmin -s /sbin/nologin kauser
[root@weblamp company]# useradd -s /sbin/nologin gyladmin
[root@weblamp company]# useradd -g gyladmin -s /sbin/nologin gyluser
[root@weblamp company]# useradd -s /sbin/nologin wpcgadmin
[root@weblamp company]# useradd -g wpcgadmin -s /sbin/nologin wpcguser
[root@weblamp company]# useradd -s /sbin/nologin administrator

#添加虚拟用户的登录密码

[root@weblamp company]# smbpasswd -a zmcsadmin
New SMB password:(123)
Retype new SMB password:
Added user zmcsadmin.
[root@weblamp company]# smbpasswd -a zmcsuser
New SMB password:(321)
Retype new SMB password:
Added user zmcsuser.

#其他在依次添加

#设置管理员密码

[root@weblamp company]# smbpasswd -a administrator
New SMB password:(设置密码:12345....)
Retype new SMB password:
Added user admin.

#设置目录属组

[root@weblamp company]# chown zmcsadmin.zmcsadmin ZMCS
[root@weblamp company]# chown hradmin.hradmin HR && chown fmadmin.fmadmin FM && chown dscsadmin.dscsadmin DSCS
[root@weblamp company]# chown flcgadmin.flcgadmin FLCG && chown gyladmin.gyladmin GYL && chown kaadmin.kaadmin KA
[root@weblamp company]# chown tsadmin.tsadmin TS && chown wpcgadmin.wpcgadmin WPCG && chown administrator.administrator SHARE
[root@weblamp company]# ll
total 40
drwxr-xr-x 2 dscsadmin dscsadmin 4096 Dec 21 14:45 DSCS
drwxr-xr-x 2 flcgadmin flcgadmin 4096 Dec 21 14:45 FLCG
drwxr-xr-x 2 fmadmin fmadmin 4096 Dec 21 14:45 FM
drwxr-xr-x 2 gyladmin gyladmin 4096 Dec 21 14:45 GYL
drwxr-xr-x 2 hradmin hradmin 4096 Dec 21 14:45 HR
drwxr-xr-x 2 kaadmin kaadmin 4096 Dec 21 14:45 KA
drwxr-xr-x 12 admin admin 4096 Dec 21 15:16 SHARE
drwxr-xr-x 2 tsadmin tsadmin 4096 Dec 21 14:45 TS
drwxr-xr-x 2 wpcgadmin wpcgadmin 4096 Dec 21 14:45 WPCG
drwxr-xr-x 2 zmcsadmin zmcsadmin 4096 Dec 21 14:45 ZMCS

#修改目录权限

[root@weblamp company]# chmod 1770 DSCS FLCG FM GYL HR KA TS WPCG ZMCS
[root@weblamp company]# chmod -R 0775 SHARE/
[root@weblamp company]# ll
total 40
drwxrwx--T 2 dscsadmin dscsadmin 4096 Dec 21 14:45 DSCS
drwxrwx--T 2 flcgadmin flcgadmin 4096 Dec 21 14:45 FLCG
drwxrwx--T 2 fmadmin fmadmin 4096 Dec 21 14:45 FM
drwxrwx--T 2 gyladmin gyladmin 4096 Dec 21 14:45 GYL
drwxrwx--T 2 hradmin hradmin 4096 Dec 21 14:45 HR
drwxrwx--T 2 kaadmin kaadmin 4096 Dec 21 14:45 KA
drwxrwxr-x 12 admin admin 4096 Dec 21 15:16 SHARE
drwxrwx--T 2 tsadmin tsadmin 4096 Dec 21 14:45 TS
drwxrwx--T 2 wpcgadmin wpcgadmin 4096 Dec 21 14:45 WPCG
drwxrwx--T 2 zmcsadmin zmcsadmin 4096 Dec 21 14:45 ZMCS
-------------------------------------------------------------
#设置共享目录属组
[root@weblamp company]#cd SHARE
[root@weblamp SHARE]# chown zmcsadmin.zmcsadmin ZMCS
[root@weblamp SHARE]# chown hradmin.hradmin HR && chown fmadmin.fmadmin FM && chown dscsadmin.dscsadmin DSCS
[root@weblamp SHARE]# chown flcgadmin.flcgadmin FLCG && chown gyladmin.gyladmin GYL && chown kaadmin.kaadmin KA
[root@weblamp SHARE]# chown tsadmin.tsadmin TS && chown wpcgadmin.wpcgadmin WPCG && chown administrator.administrator TOOLS
[root@weblamp SHARE]# ll
total 40
drwxr-xr-x 2 dscsadmin dscsadmin 4096 Dec 21 15:15 DSCS
drwxr-xr-x 2 flcgadmin flcgadmin 4096 Dec 21 15:15 FLCG
drwxr-xr-x 2 fmadmin fmadmin 4096 Dec 21 15:15 FM
drwxr-xr-x 2 gyladmin gyladmin 4096 Dec 21 15:15 GYL
drwxr-xr-x 2 hradmin hradmin 4096 Dec 21 15:15 HR
drwxr-xr-x 2 kaadmin kaadmin 4096 Dec 21 15:15 KA
drwxr-xr-x 2 admin admin 4096 Dec 21 15:15 TOOLS
drwxr-xr-x 2 tsadmin tsadmin 4096 Dec 21 15:15 TS
drwxr-xr-x 2 wpcgadmin wpcgadmin 4096 Dec 21 15:15 WPCG
drwxr-xr-x 2 zmcsadmin zmcsadmin 4096 Dec 21 15:15 ZMCS

#修改共享目录权限

[root@weblamp SHARE]# chmod 1775 CGFL
[root@weblamp SHARE]# chmod 0775 TOOLS
[root@weblamp SHARE]# ll
total 40
drwxrwxr-t 2 dscsadmin dscsadmin 4096 Dec 21 15:15 DSCS
drwxrwxr-t 2 flcgadmin flcgadmin 4096 Dec 21 15:15 FLCG
drwxrwxr-t 2 fmadmin fmadmin 4096 Dec 21 15:15 FM
drwxrwxr-t 2 gyladmin gyladmin 4096 Dec 21 15:15 GYL
drwxrwxr-t 2 hradmin hradmin 4096 Dec 21 15:15 HR
drwxrwxr-t 2 kaadmin kaadmin 4096 Dec 21 15:15 KA
drwxrwxr-x 2 admin admin 4096 Dec 21 15:15 TOOLS
drwxrwxr-t 2 tsadmin tsadmin 4096 Dec 21 15:15 TS
drwxrwxr-t 2 wpcgadmin wpcgadmin 4096 Dec 21 15:15 WPCG
drwxrwxr-t 2 zmcsadmin zmcsadmin 4096 Dec 21 15:15 ZMCS

#修改samba的配置文件

[root@weblamp SHARE]# cd /etc/samba/
[root@weblamp samba]# cp smb.conf smb.conf.ori
[root@weblamp samba]# ll
total 32
-rw-r--r-- 1 root root 20 Sep 21 18:38 lmhosts
-rw-r--r-- 1 root root 9778 Sep 21 18:38 smb.conf
-rw-r--r-- 1 root root 9778 Dec 21 15:59 smb.conf.ori
-rw-r--r-- 1 root root 97 Sep 21 18:38 smbusers

#最后编辑samba的配置文件,添加如下内容(部分实例)

[root@weblamp samba]#vim smb.conf

[CGFL]

comment = This is a directory of  DSCS.
path =/company/ DSCS/
public = no
admin users = dscsadmin
valid users = @dscsadmin
veto files = /*.mp3/*.mp4/*.rmvb/*.wma/*.exe/*.bat/*.dll/*.avi  #不允许上传的文件后缀
writable = yes
create mask = 0750
directory mask = 0750

[SHARE]
comment = This is a share directory.
path =/company/SHARE/
public = no
valid users = administrator,@dscsadmin
veto files = /*.mp3/*.mp4/*.rmvb/*.wma/*.bat/*.dll/*.avi
writable = yes
create mask = 0755
directory mask = 0755
__________________________________________
#修改配置文件后,重启samba
[root@weblamp ~]# service smb reload
#添加samba服务,开机自启动
[root@weblamp ~]# chkconfig --level 2345 smb on

[root@weblamp samba]# netstat -lntup |grep smb

tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 5349/smbd
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 5349/smbd
tcp 0 0 :::445 :::* LISTEN 5349/smbd
tcp 0 0 :::139 :::* LISTEN 5349/smbd

效果图如下:

 

 

转载于:https://www.cnblogs.com/ahtornado/p/9779510.html

你可能感兴趣的文章
解决跨操作系统平台JSON中文乱码问题
查看>>
DELPHI搭建centos开发环境
查看>>
IdHTTPServer允许跨域访问
查看>>
DELPHI开发LINUX包
查看>>
更新.net core 3.0,dotnet ef命令无法使用的解决办法
查看>>
React躬行记(13)——React Router
查看>>
前端利器躬行记(1)——npm
查看>>
前端利器躬行记(2)——Babel
查看>>
前端利器躬行记(3)——webpack基础
查看>>
前端利器躬行记(4)——webpack进阶
查看>>
前端利器躬行记(5)——Git
查看>>
前端利器躬行记(6)——Fiddler
查看>>
每次阅读外文技术资料都头疼,终于知道原因了。
查看>>
zabbix短信网关调用问题总结
查看>>
130242014034-林伟领-实验一
查看>>
Forbidden You don't have permission to access / on this server.
查看>>
Windows server 2008 R2中安装MySQL !
查看>>
Intellij Idea新建web项目(转)
查看>>
raspberry 安装apache2,使其支持ssl ,并创建自签名证书
查看>>
Trie树:应用于统计和排序
查看>>