安装配置samba

Published by davidliu on

一、环境:

CentOS 7.2

Samba 4.8.3

二、需求:

使用Samba搭建文件服务器。

(1)smbgrp组成员(tom,jack,david)可以修改及删除betterit360-publicdocs共享文件夹下目录名、文件名及文件内容。

(2)smbgrp组成员(tom,jack,david)可以修改及删除betterit360-personaldocs共享文件夹下自己创建的目录、文件,但不能修改及删除别人创建的目录、文件,也不能在别人创建的目录下创建子目录或文件,只可以查看。

(3)所有人员无需身份验证即可访问betterit360-tools共享文件夹,但只能查看,不能修改、删除。

三、安装及配置:

# yum -y install samba

查看安装版本:

# yum list installed | grep samba

# cd /etc/samba/

# mv smb.conf smb.conf.ori //备份默认配置文件

# vi smb.conf //创建新的配置文件

写入如下内容:

[global]

        workgroup = SAMBA

        security = user

        passdb backend = tdbsam

        printing = cups

        printcap name = cups

        load printers = yes

        cups options = raw

        map to guest = Bad User

[betterit360publicdocs]

       path = /sambashare/betterit360-publicdocs

       public = no

       create mask = 0775

       directory mask = 0775

       writable = yes

       valid users = @smbgrp

[betterit360-personaldocs]

       path = /sambashare/betterit360-personaldocs

       public = no

       create mask = 1744

       force create mode = 1744 //强制设置创建文件的默认权限,1表示设置sticky

       directory mask = 1755

       force directory mode = 1755 //强制设置创建目录的默认权限,1表示设置sticky

       writable = yes

       valid users = @smbgrp

[betterit360tools]

       path = /sambashare/betterit360tools

       public = yes

       writable = no    //所有人员无需身份验证即可查看及修改:writable = yes

保存并退出。

创建用户:

# groupadd smbgrp

# useradd -g smbgrp -M -s /sbin/nologin tom

# useradd -g smbgrp -M -s /sbin/nologin jack

# useradd -g smbgrp -M -s /sbin/nologin david

# smbpasswd -a tom

New SMB password:

Retype new SMB password:

Added user tom.

# smbpasswd -a jack

New SMB password:

Retype new SMB password:

Added user jack.

# smbpasswd -a david

New SMB password:

Retype new SMB password:

Added user david.

创建共享目录并设置权限:

# mkdir -p /sambashare

# mkdir -p /sambashare/betterit360-publicdocs

# mkdir -p /sambashare/betterit360-personaldocs

# mkdir -p /sambashare/betterit360-tools

# chmod -R 775 /sambashare/betterit360-publicdocs

# chmod -R 775 /sambashare/betterit360-personaldocs

# chmod -R o+t /sambashare/betterit360-personaldocs //此步若省略,则betterit360-personaldocs目录下创建的目录名、文件名,其他用户可以修改等。

# chmod -R 775 /sambashare/betterit360-tools

# chgrp -R smbgrp /sambashare/betterit360-publicdocs

# chgrp -R smbgrp /sambashare/betterit360-personaldocs

# chgrp -R smbgrp /sambashare/betterit360-tools

启动Samba:

# testparm    //测试Samba配置文件是否正确

# systemctl start smb //启动Samba

注:

systemctl restart smb //重启

systemctl enable smb //修改为开机启动

systemctl status smb //查看状态

四、 客户端测试访问(可以使用windows客户端测试,更直观):

示例图 :

附录:

windows 10 无法访问 CentOS 7 的 SMB 共享文件问题解决

不同的问题症状可参考如下不同的解决办法:

(1)修改 Win10 策略。按window+R键输入gpedit.msc 来启动本地组策略编辑器。依次找到“计算机配置-管理模板-网络-Lanman工作站”这个节点,在右侧内容区可以看到“启用不安全的来宾登录”这一条策略设置。状态是“未配置”,双击它,将其状态修改为“已启用”并单击确定按钮。

(2)进入Control Panel\Programs,点击【Turn Windows feautres on or off】,勾选 SMB 1.0/CIFS File Sharing Support 下的 SMB 1.0/CIFS Client 和 SMB 1.0/CIFS Server,点击【ok】,然后,重启电脑。

Categories: Uncategorized

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *