zoukankan      html  css  js  c++  java
  • linux_samba服务搭建

    什么是samba服务?

          用于Windows和linux系统之间实现共享文件的目的服务

    如何配置其服务?

          Linux端: 搭建服务

      1. 安装samba

    yum install -y samba

      2. 配置个人网盘服务(这里还有配置大家都可以访问的网盘内容,叫公有,后说)

        # 不需要修改任何配置 

        a. 添加登录网盘的用户,这个用户必须是 linux系统的用户

    useradd beimenchuixue -s /sbin/nologin

        b. 通过smbpasswd添加一个samba用户并设置密码

    smbpasswd -a beimenchuixue

        c. 启动samba服务并且加入开机自启动

    /etc/init.d/smb start
    chkconfig smb on 

          Windows端: 连接samba服务

      1. 我的电脑,右键,映射网络驱动器

        

      2. 输入 \linux主机ip地址samba用户,勾选上其他凭证连接

        # 首先windows能与linux通信,并且linux关闭selinux和防火墙放行samba服务

        

      3. 输入设置的密码

        

      4. 连接完成后,可以像本地磁盘一样打开,写入数据

        # 在Windows下向这个网盘写入数据,都会压缩为该用户对应linux用户的权限

    Samba公有网盘搭建

           Linux端: 修改相关配置文件

      1. 修改配置文件,其配置文件位置: /etc/samba/smb.conf

    cp  /etc/samba/smb.conf{,$(date +%F)}
    sed -i "s/security = user/security = share/g" /etc/samba/smb.conf
    sed -i '$a [company]
        comment=share file
        path=/company
        public=yes
        writable=yes' /etc/samba/smb.conf

        # 还有其他相关配置,公有的总会带来安全问题

        # comment= 设置共享注释

        # path= 设置共享目录的物理路径

        # public=yes|no   设置资源是否能给游客账号访问

        # valld user=@group_name,user_name 设置允许哪些合法组和用户访问

        # browseable=yes|no 设置该共享为隐藏共享

        # writable=yes|no 设置是否允许客户端写入数据

        # hosts allow=     设置允许访问该共享的合法网段或ip

        # printable=yes|no 接打印机

      2.  限制上传的目录权限为755,文件权限为644

    sed -i " /[company]/a     create mask = 0644
    
        force create mode = 0644
    
        directory mask = 0755
    
        force directory mode = 0755
        " /etc/samba/smb.conf

      3. 创建共享目录,授权写权限,在linux相当于其他人

    mkdir /company
    chmod -R o+w /compay

      4. 重启samba服务

    /etc/init.d/smb restart

           Window端: 连接samba服务

      1. 连接samba服务,注意把上面的用户名换为模块company

        

                  # 至此,samba服务搭建完成,samba有两种安全验证,一种是share一种是user

          # 注意创建公有网盘服务时候,不能有samba网盘用户,需要使用smbpasswd -x username删除已经添加的所有smb用户,不删除会在Windows端写入数据时候会卡住

          # 既然作为一个公有盘,做报表展示或其他通知相关信息展示,可以在linux端收回这个company目录的其他人的写权限

    一键搭建samba私有网盘

    #!/bin/sh
    
    # author: beimenchuixue
    # email: 422083556@qq.com
    # blog: http://www.cnblogs.com/2bjiujiu/
    
    . /etc/init.d/functions
    
    login_password="123456"
    login_user="beimenchuixue"
    model="workspace"
    samba_conf_file="/etc/samba/smb.conf"
    
    install_samb() {
        yum install -y samba &> /dev/null
        [ $? -eq 0 ] && {
            action "samb server install is" /bin/true
        } || {
            action "samb server install is" /bin/false
            exit 1
        }
    }
    # install_samb
    
    add_samba_user() {
        id $login_user &> /dev/null
        [ $? -eq 0 ] || {
            useradd $login_user -s /sbin/nologin
        }
        action "samba_user is" /bin/true
    }
    # add_samba_user
    
    install_expect() {
        yum install -y expect &> /dev/null
        [ $? -eq 0 ] || {
            action "install_expect is" /bin/false
            exit 2
        }
        action "install_expect is" /bin/true
    }
    # install_expect
    
    set_user_pwd() {
        `which expect` <<jia
        set timeout -1
    
        spawn smbpasswd -a $login_user
        expect {
            "*password:" {send "${login_password}
    ";exp_continue}
        }
    jia
        [ $? -eq 0 ] && {
            action "set password is" /bin/true
        } || {
            action "set password is" /bin/false
            exit 3
        }
    }
    # set_user_pwd
    
    init_start_smb() {
        /etc/init.d/smb restart &> /dev/null
        chkconfig smb on
        action "start smb is" /bin/true
    }
    # init_start_smb
    
    main() {
        install_samb
        add_samba_user
        install_expect
        set_user_pwd
        init_start_smb
    }
    main
    

      

     

  • 相关阅读:
    toj 2819 Travel
    toj 2807 Number Sort
    zoj 2818 Prairie dogs IV
    zoj 1276 Optimal Array Multiplication Sequence
    toj 2802 Tom's Game
    toj 2798 Farey Sequence
    toj 2815 Searching Problem
    toj 2806 Replace Words
    toj 2794 Bus
    css截取字符
  • 原文地址:https://www.cnblogs.com/2bjiujiu/p/8397765.html
Copyright © 2011-2022 走看看