Linux中Samba文件服务

作者: 少帅yangjie | 来源:发表于2018-05-15 23:03 被阅读23次

    安装samba的服务器

            yum install samba

    此时安装的是samba而不是samba-client,安装完成之后可以通过/etc/samba/smb.conf来修改这个配置文件,可以通过smb.conf.example来查询一个实例,如果希望过滤掉查询出来的注释可以使用如下命令

            grep-v'^#'/etc/samba/smb.conf.example |grep-v"^;"|grep-v"^$"

    grep -v用来过滤一些信息,'^#'表示过滤#号开头的信息,^;表示过滤;开头的信息,^$表示过滤空格。

    安装完成之后使用

            systemctlstartsmb##启动samba

    使用systemctl status smb 查询samba的状态

    通过修改配置文件来设置samba的服务

            [global]##表示的是全局配置

            workgroup=MYGROUP

            server string=Samba Server Version %v

            # log files split per-machine:

            log file=/var/log/samba/log.%m

            # maximum size of 50KB per log file, then rotate:

            max log size=50

            security=user##授权方式,user表示基于用户名和密码授权,share表示不用用户名和密码都可以访问

            passdb backend=tdbsam

            # the following login script name is determined by the machine name

            # (%m):

            # the following login script name is determined by the UNIX user used:

            # use an empty path to disable profile support:

            # various scripts can be used on a domain controller or a stand-alone

            # machine to add or delete corresponding UNIX accounts:

            load printers=yes

            cups options=raw

            # obtain a list of printers automatically on UNIX System V systems:

            [homes]##只要创建了一个用户,就会默认开启该用户的home文件夹中的用户的主文件的访问

            comment=Home Directories

            browseable=no## 表示只显示自己的用户的文件夹

            writable=yes##是否具备写的操作

    关闭selinux,修改/etc/selinux/config文件

            将SELINUX=enforcing改为SELINUX=disabled

            设置后需要重启才能生效

    关闭防火墙

            systemctlstopfirewalld

    使用

            systemctl disable firewalld

    可以开机不再启动防火墙。

    samba的用户就是linux中的用户,但是,密码需要是独立的samba密码,用户的原密码是无法使用的,需要通过如下命令来设置用户的密码

            smbpasswd –a user 添加一个用户

            smbpasswd –d user 禁用一个用户

            smbpasswd –e user 启用一个用户

            smbpasswd –x user 删除一个用户

    如果在window中已经记住了一个samba服务的用户名和密码,第二次使用的时候会自动打开第一个用户的文件夹,所以此时可以使用window中的net use命令来清空缓存

            C:\Users\konghao>net use

            会记录新的网络连接。

            状态       本地        远程                      网络

            -------------------------------------------------------------------------------

            OK                     \\192.168.213.122\IPC$ Microsoft Windows Network

            命令成功完成。

            C:\Users\konghao>net use * /DELETE

    完整的配置流程

            1、安装samba的服务

            2、关闭selinux和firewalld

            3、开启samba的服务

                        systemctlstartsmb

    4、配置/etc/sabma/config

            [global]

                workgroup=SAMBA

                security=user

                passdb backend=tdbsam

                printing=cups

                printcap name=cups

                load printers=yes

                cups options=raw

                writable=Yes

            [homes]

                comment=Home Directories

                valid users=%S, %D%w%S

                browseable=No

                read only=No

                inherit acls=Yes

    5、设置samba的登录用户密码

                smbpasswd-atest

    6、在window中使用UNC的方式访问  \192.168.xx.xx

    相关文章

      网友评论

        本文标题:Linux中Samba文件服务

        本文链接:https://www.haomeiwen.com/subject/hrkudftx.html