Mint17 https://www.e-learn.cn/tag/mint17 zh-hans Mint17/Ubuntu14.04 samba文件服务器搭建 https://www.e-learn.cn/topic/2113784 <span>Mint17/Ubuntu14.04 samba文件服务器搭建</span> <span><span lang="" about="/user/191" typeof="schema:Person" property="schema:name" datatype="">末鹿安然</span></span> <span>2019-12-10 14:51:49</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <span id="OSC_h2_1"></span> <h2>一、简介<br /></h2> <p><span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">    Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。</span><a target="_blank" href="http://baike.baidu.com/view/262410.htm" rel="nofollow"><span style="color: rgb(0, 0, 0);">SMB</span></a><span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">是一种在</span><a target="_blank" href="http://baike.baidu.com/view/788.htm" rel="nofollow"><span style="color: rgb(0, 0, 0);">局域网</span></a><span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">上共享文件和打印机的一种</span><a target="_blank" href="http://baike.baidu.com/view/185322.htm" rel="nofollow"><span style="color: rgb(0, 0, 0);">通信协议</span></a><span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置“NetBIOS over TCP/IP”使得Samba不但能与局域网络主机分享资源,还能与全世界的电脑分享资源。</span></p> <p style="text-align: center;"><span style="color: rgb(51, 51, 51); font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 24px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">二、搭建步骤</span><span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);"><br /></span></p> <p><span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">1、使用包管理器</span><span style="font-size: 14px;"><span style="font-family: 宋体;">安装S</span><span style="font-family: 'Times New Roman';">amba</span><span style="font-family: 宋体;">服务器</span></span></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>sudo apt-get install samba</code></pre> <p><span style="font-family: arial, helvetica, sans-serif;"><span style="color: rgb(51, 51, 51); font-size: 14px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">2、</span><span style="font-size: 16px;">备份</span><span style="font-size: 16px;">samba</span><span style="font-size: 16px;">配置文件,避免错误配置,便于及时回退之前的状态</span></span></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code> sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak</code></pre> <p><span style="font-family: 宋体; font-size: 16px;">3.创建共享目录</span></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>注释:/home/share可以指定为一个合法的路径即可 sudo mkdir -p /home/share</code></pre> <p><span style="font-family:宋体;font-size:16px">4.</span><span style=";font-family:宋体;font-size:16px">修改配置文件</span></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>sudo vim /etc/samba/smb.conf</code></pre> <p><span style="font-family:宋体"><span style="font-size: 16px;">5、例如此时为所有的用户创建一个共享目录,此时</span></span><span style="font-family: 宋体; font-size: 16px;">在配置文件</span><span style="font-size: 16px; font-family: 'Times New Roman';">smb.conf</span><span style="font-family: 宋体; font-size: 16px;">最后添加如下:</span></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>[共享] Commnet = “xxxxxx”                注释:该共享目录的描述 Path = “/home/share”              注释:设置共享目录为/home/share Avaliable = yes/no                注释:设置共享目录是否可显示 Writable = yes/no                 注释:指定该目录缺省是否可写,也可以用readonly = no来设置可写 Browseable  = yes/no              注释:设置共享目录是否可显示</code></pre> <p>以下为附加选项:</p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>Public yes/no                     注释:指明该共享资源是否能给游客账号访问 Valid users = zhaop_os            注释:samba账户名,这里是指此文件夹的合法用户为zhaop_os,若需要添加组,那么可以写成valid users = zhaopei_os,@group Invalid users =XX                 注释:zengxs_os //指定不能使用的用户和组 Readlist users =                  注释:/指定能读取和写共享文件的组 write list = user, @group        注释:  指定能读取和写该共享资源的用户和组 admin list = user, @group        注释:指定能管理该共享资源(包括读写和权限赋予等)的用户和组 ide dot files = yes|no            注释: 指明是否像UNIX那样隐藏以“.”号开头的文件 create mode = 0755               注释: 指明新建立的文件的属性,一般是0755 directory mode = 0755             注释:# 指明新建立的目录的属性,一般是0755 sync always = yes|no              注释:# 指明对该共享资源进行写操作后是否进行同步操作 short preserve case = yes|no      注释:# 指明是否区分文件名大小写 preserve case = yes|no           注释:# 指明是否保持大小写 case sensitive = yes|no          注释:# 指明是否对大小写敏感,一般选no,不然可能引起错误 mangle case = yes|no             注释:# 指明混合大小写 default case = upper|lower       注释:# 指明缺省的文件名是全部大写还是小写 force user = testuser            注释:# 强制把建立文件的属主是谁。如果我有一个目录,让guest可以写,那么guest就可以删除,如果我用force user= testuser强制建立文件的属主是testuser,同时限制create mask = 0755,这样guest就不能删除了 wide links = yes|no              注释:# 指明是否允许共享外符号连接,比如共享资源里面有个连接指向非共享资源里面的文件或者目录,如果设置wide links = no将使该连接不可用 max connections = 100            注释:# 设定最大同时连接数 delete readonly = yes|no         注释:# 指明能否删除共享资源里面已经被定义为只读的文件</code></pre> <p><span style="font-family:宋体;font-size:16px">6、</span><span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">创建<span style="font-family: arial, helvetica, sans-serif;">samba用户</span></span></p> <p><span style=";font-family:宋体;font-size:16px">例如为配置文件中的<span style="font-family:Times New Roman">users</span><span style="font-family:宋体">创建</span><span style="font-family:Times New Roman">zhaop_os,</span></span><span style="font-family: 宋体; font-size: 16px;">执行以下两个步骤:</span></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>1.sudo useradd zhaop_os 2.sudo smbpasswd zhaop_os</code></pre> <p><span style="font-family:宋体;font-size:16px">7、</span><span style="font-family: 宋体; font-size: 14px;">重启<span style="font-family: 'Times New Roman';">samba</span>服务</span></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>1. sudo testparm               注释:查看载入的samba配置文件的内容,检查是否出错 2. sudo service reload         注释:重新载入配置文件 3. sudo service restart        注释:重启samba服务</code></pre> <p>Add-ons:我的samba私有文件夹具体配置过程</p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>mkdir -p /home/pri/zhaopei_os</code></pre> <p>增加配置文件内容如下:</p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>【zhaop_os】 Commnet = “xxxxxx”                注释:该共享目录的描述 Path = “/home/pri/zhaopei_os”       注释:设置共享目录为/home/share Avaliable = yes/no                注释:设置共享目录是否可显示 Writable = yes/no                 注释:指定该目录缺省是否可写,也可以用readonly = no来设置可写 Browseable  = yes/no Public yes/no                     注释:指明该共享资源是否能给游客账号访问 Valid users = zhaop_os            注释:samba账户名,这里是指此文件夹的合法用户为zhaop_os,若需要添加组,那么可以写成valid users = zhaopei_os,@group</code></pre> <p>创建对应的关联samba用户<br /></p> <pre class="brush:shell;toolbar: true; auto-links: false;"><code>1.sudo useradd zhaop_os 2.sudo smbpasswd zhaop_os</code></pre> <p style="text-align: left;"><span style="color: rgb(51, 51, 51); font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 24px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">常见question</span></p> <p style="text-align: left;"><span style="color: rgb(51, 51, 51); font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 24px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);"></span></p> <span id="OSC_h2_2"></span> <h2><span style="font-size: 14px;">1.win7访问Linux Samba的共享目录提示“登录失败:用户名或密码错误”解决方法;</span></h2> <p>解决方法:见链接<a href="http://blog.sina.com.cn/s/blog_72aace390100r042.html。" rel="nofollow">http://blog.sina.com.cn/s/blog_72aace390100r042.html。</a><br /></p> <p><strong>2.长时间连接后,出现失去连接的情况;</strong><br /></p> <p style="text-align: left;"><span style="color: rgb(51, 51, 51); font-family: 微软雅黑,'Microsoft YaHei'; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255); font-size: 14px;">解决方法:根据日志分析。<br /></span><br /></p> <p><span style="color: rgb(51, 51, 51); font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 24px; line-height: 24px; text-indent: 28px; background-color: rgb(255, 255, 255);">三、搭建过程中的心得</span><br /><span style="font-family: 宋体; font-size: 14px;"></span></p> <ol><li><p>便于管理用户账户和密码可以在/etc/samba目录下创建一个smbusers.</p></li> <li><p>当客户端访问smb服务器的连接已经打开,此时服务器重启以后,客户端需要重启才能重新完成此次连接。</p></li> <li><p>windows在地址栏中输入//XXXXXX,最后出现访问拒绝的情况,在确认服务器配置无误并且用户名存在的情况下,可以修改windows的本地策略,可以参照一下http://blog.sina.com.cn/s/blog_7291f6ad0100xedv.html。<br /></p></li> </ol><p>    本人搭建的过程远远不像自己写文章这么的一气呵成,尝试,failed,尝试,failed,四五个来回总算基本能使用和部署samba服务器了。人生也是如此,贵在尝试,贵在坚持,我想若干年后看看曾经写过的东西,回想一路的艰辛,那一刻该有多么美好。</p> <div class="alert alert-success" role="alert"><p>来源:<code>oschina</code></p><p>链接:<code>https://my.oschina.net/u/2496664/blog/521806</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/ubuntu1404" hreflang="zh-hans">Ubuntu14.04</a></div> <div class="field--item"><a href="/tag/mint17" hreflang="zh-hans">Mint17</a></div> <div class="field--item"><a href="/tag/samba" hreflang="zh-hans">samba</a></div> <div class="field--item"><a href="/tag/wenjiangongxiang" hreflang="zh-hans">文件共享</a></div> <div class="field--item"><a href="/tag/yuanchuang" hreflang="zh-hans">原创</a></div> </div> </div> Tue, 10 Dec 2019 06:51:49 +0000 末鹿安然 2113784 at https://www.e-learn.cn