博客
关于我
如何实现Samba文件共享服务
阅读量:663 次
发布时间:2019-03-15

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

CentOS 7环境搭建Samba文件共享服务器Marvelous Configuration Guide

在本文中,我们将介绍如何在 CentOS 7 环境中配置并运行一个功能性能优越的Samba文件共享服务器。该服务器将使您能够轻松共享文件,适用于内部网络中的小型到中型服务器环境。本文将涵盖从安装服务到配置用户认证以及匿名共享的完整流程。


服务端操作

操作步骤

  • 关闭防火墙并禁止SELinux

    通过临时禁用防火墙以避免干扰:

    root@hejie ~]# setenforce 0root@hejie ~]# systemctl stop firewalld

    注意:建议在完成配置后重新启用防火墙。

  • 安装Samba软件包

    使用Yum العلوم包管理器安装所需的软件包:

    root@hejie ~]# yum install samba-* -y
  • 启动并设置Smb服务自启动

    启动Samba服务并确保其在系统启动时自动启动:

    root@hejie ~]# systemctl start smbroot@hejie ~]# systemctl enable smb

    确认:执行以上命令后,系统将 创建一个SYMLINK,指向实际的SMB服务文件。

  • 配置Samba配置文件

    最终,确保所有参数都插入配置文件中。默认配置文件位于 /etc/samba/smb.conf )。

    以下是推荐的主要配置参数:

    [global]    workgroup = SAMBA    security = user    passdb backend = tdbsam    printing = cups    printcap name = cups    cups options = raw

    提示:在[global] 部分添加 username map = /etc/samba/smbusers 以支持多用户映射。

  • 创建并配置共享目录

    • 创建一个用于共享的目录(例如 /opt/zhengran)并设置权限:
    root@hejie ~]# mkdir /opt/zhengranroot@hejie ~]# chown -R zhengran:zhengran /opt/zhengran
  • 添加用户并设置权限

    使用useradd创建用户并设置密码:

    root@hejie ~]# useradd -M zhengranroot@hejie ~]# smbpasswd -a zhengran

    在完成后,建议添加用户映射到 /etc/samba/smbusers 中:

    root@hejie ~]# echo 'zhengran = share' >> /etc/samba/smbusers
  • 配置共享选项

    在Samba配置文件中添加新的共享定义(例如,在 /etc/samba/smb.conf 中):

    [zhengran]    comment = Home Directories    path = /opt/zhengran    browseable = yes    writable = yes    write list = share    public = yes
  • 验证配置文件

    使用 testparm检查Samba配置文件是否正确无误:

    root@hejie ~]# testparm

    输出应不包含错误信息。

  • 重启Samba服务

    使所有更改生效:

    root@hejie ~]# systemctl restart smb

  • 客户端操作

    操作步骤

  • 安装客户端工具

    在客户端上安装必要的软件包:

    root@hyj ~]# yum install samba-client cifs-utils -y
  • 查看共享资源

    使用 smbclient 检索远端共享资源:

    root@hyj ~]# smbclient -L 192.168.56.11 -U share

    提示输入用户密码,输入share的密码即可。

  • 挂载共享资源

    将共享目录挂载到客户端指定的目录:

    root@hyj ~]# mount -t cifs //192.168.56.11/zhengran /opt/ran -o username=share,password=123
  • 创建与写入文件

    在本地挂载点创建新文件:

    root@hyj ~]# mkdir /opt/ranroot@hyj ~]# touch 1 2 3root@hyj ~]# ls 1 2 3

  • 匿名共享配置

    服务端操作

  • 修改配置文件

    修改Samba配置文件以允许多个匿名用户访问共享目录。

    root@hejie ~]# vim /etc/samba/smb.conf

    [global] 部分添加以下内容:

    map to guest = Bad User
  • 创建匿名共享目录

    创建一个共享目录并设置适当权限:

    root@hejie ~]# mkdir /opt/ranranroot@hejie ~]# chmod 777 /opt/ranran
  • 配置匿名共享选项

    在Samba配置文件中添加匿名共享部分:

    [ran]    comment = ranranwoaini    path = /opt/ranran    browseable = yes    writable = yes    guest ok = yes    public = yes
  • 重启Samba服务

    使新的配置生效:

    root@hejie ~]# systemctl restart smb

  • 在完成以上步骤后,客户端可以使用匿名账户即可访问共享资源。这样,您的文件共享服务器配置已经完成,能够满足内部小型网络的需求。

    转载地址:http://ggvmz.baihongyu.com/

    你可能感兴趣的文章
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    no1
    查看>>
    NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
    查看>>
    NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    node exporter完整版
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
    查看>>
    Node 裁切图片的方法
    查看>>
    Node+Express连接mysql实现增删改查
    查看>>