Construction and configuration of Samba server under LINUX (basic version)

Introduction to SMB

SMB (server message block, service message block) is a protocol for sharing files and printers on a local area network. It was developed by Intel and Microsoft and can run on a variety of protocols such as TCP/IP or IPX. Its main function is to provide file system and print services for Windows system hosts and Linux system hosts on the same network. The SMB protocol is a client and server mode. In addition to sharing resources on the same local area network, it can also use NetBIOS over TCP/IP to share resources with computers all over the world.

Introduction to Samba

Samba includes a set of software packages that enable linux to support the smb protocol, which is the basis for Windows to enable linux file and printer sharing. It is primarily responsible for handling and using remote files and resources. Samba is released based on gpl and maintained by the Samba team. At the heart of Samba are two daemons, smbd and nmbd. They listen on port 139tcp and handle incoming smb packets and listen on ports 137 and 138udp respectively and enable other host resources to browse the linux server.

Samba mainly has the following functions:

1. Use Windows to be able to share files and printers

2. Share the printer installed on the Samba server

3. Share the file system of linux

4. Support Windows clients to browse the Internet using My Network Neighborhood

5. Support Windows domain controller and Windows member server to authenticate users who use Samba resources

6. Support wins name server resolution and browsing

7. So far SSL secure socket layer protocol

Samba application environment

1. File and printer sharing. This is the main function of Samba. The SMB process realizes resource sharing and publishes files and printers to the network for user access.

2. Authentication and permission settings. The Samba service supports authentication and permission setting modes such as user mode and domain mode, and can protect shared files and printers through encryption.

3. Name resolution. Samba can build an NBNS (netbios name service) server through the nmbd server, provide name resolution, and resolve the computer's netbios name into an ip address.

4. Browse Services. In a local area network, the Samba server can become a local master browser (LMB), keeping a list of available resources. When using the client to access Windows Network Neighborhood, a browse list will be provided to display resources such as shared directories and printers.

How Samba Works

Samba mainly uses two protocols, one is the NETBIOS (Windows "Network Neighborhood" communication protocol) protocol, and the other is the SMB (server message block) protocol. These two protocols run on top of the tcp/ip communication protocol and use Windows' NETBEUI protocol to make linux visible to Windows over "network protocols".

The SMB protocol is very important. It is widely used in Windows series operating systems. It is an abstract protocol for sharing printers, serial ports and communication between different computers. Samba is a server that runs on Unix-like systems using the SMB protocol. Currently, Samba can run on almost all Unix variants.

Samba related processes

The Samba service consists of two processes, nmbd and smbd. What it does is:

(1) nmbd: Performs NetBIOS name resolution and provides a browser service to display a list of shared resources on the network.

(2) smbd: Manage shared directories, printers, etc. on the Samba server. Mainly for the management and service of shared resources on the network. When accessing the server to find shared files, it is necessary to rely on the smbd process to manage data transmission.

Let's introduce the construction of Samba server

Let's see if linux has installed all the rpm packages required by Samba

(Note: The Samba service name is smb, and the package name is still samba)

Here the editor has already done it, so it is all installed. By default, there are only the first four rpm packages, and then we find the rpm package in the server folder.


That's it, this rpm package is not installed by default, we can click it to install it

Like what the editor said earlier, the Samba service can be started without any configuration, so the editor will talk a little more about the startup of the service (take the smb service as an example)

1. Graphical interface


We find it in turn: System--Administration--Server Settings--Services, and then open it

这里就是可以对任何服务进行操作(当然了,对于那些需要配置的服务来说,也是启动不了的),也可以将其设置为开机自启动,我们开启服务后点击保存就可以了。如果不点击保存,仅仅开启服务,下次开机默认还是关闭的。下面,我们开启smb服务。点击开始


我们可以看到smb服务正在运行

2.命令行模式

(1)service smb restart(start)(stop)

(2)/etc/re.d/init.d/smb restart(start)(stop)

因为这种启动模式是我们最熟悉的,这里小编就不再解释

设置开机自启动

刚才已经说过图形界面下进行设置开机自启动,然后小编再介绍两种方式

(1)chkconfig命令

chkconfig 【-level n(n表示数字)】可写可不写,不写的话默认运行级别为5, +smb(服务名,这里以smb服务举例)+ on/off 是否自启动

(2)ntsysv命令


在这里我们选择服务名,然后确认保存就可以了,反之,取消不保存就OK。

Samba服务日志文件

Samba服务的日志文件默认存放在/var/log/samba中,Samba服务为所有连接到Samba服务器的计算机建立个别日志文件,同时也将NMB服务和SMB服务的运行日志分别写入nmbd.log和smbd.log日志文件中。管理员可以通过这些日志文件查看用户的访问情况和服务的运行状态。

在/etc/samba/smb.conf文件中,log file为设置Samba日志的字段,如下所示。


日志文件默认放在/var/log/samba/中,其中Samba会为每个连接到Samba服务器的计算机分别建立日志文件。使用ls -a命令查看日志目录的所有文件


其中:Samba服务器刚建立时只有两个日志文件,分别是nmbd.log和smbd.log。他们分别记录nmbd和smbd进程的运行日志。Nmbd.log记录nmbd进程的解析信息。Smbd.log记录用户访问Samba服务器的问题,以及服务器本身的错误信息。可以通过该文件获取大部分Samba的维护信息。

当客户端通过网络访问Samba服务器后,会自动添加客户端的相关日志。管理员可以根据这些文件来查看用户的访问情况和服务器的运行情况。另外,当Samba服务器工作异常时,也可以通过/var/log/Samba下的日志进行分析。

Samba服务器的密码文件

客户端访问Samba服务器时,需要提交用户名和密码进行身份验证,验证合格才可以登录。Samba服务器将用户名和密码的信息存放在/etc/Samba/smbpasswd中。在客户端访问时,将用户提交的资料与smbpasswd存放的信息进行比对。如果二者相同,并且Samba服务器其他安全设置允许,客户端与Samba服务器的连接才能成功。

如果要Samba服务器正常工作,那还是要靠主配置文件smb.conf啦

它的全目录是/etc/samba/smb.conf

这个配置文件还是比较好的,层次分明,改错也是比较好改的

分为两大部分(其实还有其他部分,不过不太重要,这里就介绍这两部分)

1.Global Settings

用来设置全局变量区域。如果在此进行了设置,那么该设置就可以针对所有的共享资源生效。(感觉有点像编码的css样式,整体样式和局部样式,如果某部分样式未定义,就采用整体样式的规定)可根据需求设置。

2.Share Definitions 共享服务的定义

share definitions设置对低昂为共享目录和打印机。如果要发布共享资源,就需要对share definitions字段部分进行配置。share definitions字段非常丰富,设置灵活。根据需求灵活运用。

下面就开始实际运用了


global全部变量配置部分,小编来逐个解释

workgroup=WORKGROUP:定义一个叫WORKGROUP的工作组

server string=file server      :注释作用,根据需求对这个服务器进行定义

Security=share                    :安全级别为share(一共有五中级别:1.share 2.user 3.server 4.domain 5.ads安全系数依次增强,后面用到时再做解释)

public=yes                           :是否共享

browseables=yes                 :是否允许用浏览器访问

directory=777 creare mask=777这是一开是小编排错的时候加的,发现不影响运行,就是设置目录权限和设置目录的掩码,这里的权限我们直接在外部用chmod更改权限就可以代替。所以这两行可以不写。  


[ ]                     :中括号里面的内容就是我们的目录名

comment        :注释说明

public=yes      :是否共享(与security = share连用 

guest ok=yes  :是否允许匿名身份登录

这里小编共享了两个目录,然后重启smb服务


我们还可以用一个命令查看一下我们的配置信息(testparm -s)


由于小编一开始做的并不顺利,也换了系统访问,最后都解决了。下面小编就来介绍win7(user安全级别:需要验证)和xp系统(share安全级别:直接访问,不需要验证)下对于Samba服务器的访问

1.WIN7

Samba下的共享是针对局域网内的,由于一开始搭建了dhcp服务器,这里我们分配的ip地址自动就在一个网段内了。

我们直接在资源管理器中输入\\192.168.10.6(Samba服务器的ip地址),然后回车


出现了验证界面,这里要补充一下,这里的用户要是Samba用户,Samba用户与linux用户的关系是,Samba用户必须是linux用户转化而来,所以我们要建立Samba用户,我们必须要建立linux用户

由于tom用户我们已经建立,这里就拿tom2来举例


这里我们建好了linux用户,然后我们将其变成Samba用户


这里的密码还要重新设置,这里的用户名和密码就是我们在win7下登录的用户名和密码


这里我们已经看到了我们共享的文件夹:路径是/usr/mez


这里由于是第一次做的实验,所以只能看见文件夹,而看不到里面的内容(出现了权限不足,拒绝访问),小编也检查了好多遍,最后把解决经验分享给大家

1.在WIN7或VISTA下,因为Samba只支持NTLM认证,而WIN7或VISTA则采用NTLMv2认证,所以我们要进行设置


我们在运行面板中输入:secpol.msc(打开本地安全策略面板)


找到本地策略--安全选项--网络安全:lan管理器身份验证级别


这里小编已经改好了,默认的情况下是未定义的,这里选择发送lm和ntlm-如果已协商,则使用...这一个选项,然后应用

2.文件夹的权限,为了保险起见,把文件夹的权限设置成777,因为默认的权限无法打开我们共享的文件夹,还有就是,文件夹里的文件也要设置为777,每个文件都是,就这个问题一开始为难了小编好久,只有这样,才能看到文件里面的内容,如果大家还有更好的办法,可以告诉小编。


OK,这就是小编遇到的需要两点注意的地方,然后我们再去访问,发现文件夹文件都可以打开



2.Windows xp下

这里因为安全级别为share,所以不需要验证,所以我们也不需要Samba用户直接在资源管理器中输入\\Samba服务的ip地址来访问


我们一开始已经把权限设置好,所以也可以直接打开我们想要打开的文件(注:同一网段,在一个局域网内)



OK,linux下Samba服务器的搭建已经完成,后期还会有所补充,祝大家成功!!!







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325611929&siteId=291194637