What is SAMBA? Samba: installation, configuration, optimization of work Configuring samba server under Linux.


Samba is software for organizing file exchange and working with shared resources between computers running Linux / Unix and Windows operating system. Samba consists of a client-side and a server-side. The client side allows you to access network folders and Windows resources, and the server side, in turn, opens shared access to the Ubuntu folder for other machines, including Windows.

This short tutorial will walk you through the simplest setup of Samba Ubuntu 18.04, as well as how to set up shared access to the Ubuntu folder with multiple privilege levels.

We will create three shared folders with different permission levels. A folder with anonymous access, with access for users belonging to a specific group and access only for a specific user.

Both Linux and Widnows machines will be able to access shared folders in Ubuntu, using any program that works over the SMB protocol.

For everything to work properly, all machines must be in the same workgroup specified on the Samba server. By default, for Windows, Linux and MacOS, the workgroup is named Workgroup. To find out which workgroup is used in your Windows, open a command prompt (Win + R, then cmd) and run the following command:

net config workstation

We see the parameter we need in the line Workstation domain... This is the working group.

Now, if a computer with a Samba server in your network has a permanent IP address, it is advisable to enter it in the hosts file. To do this, run Command Prompt as administrator:

And run the command:

notepad C: \ Windows \ System32 \ drivers \ etc \ hosts

In the file that opens, add a line with the IP address of the computer on which Samba will be installed:

192.168.0.1 srvr1.domain.com srvr1

Now you can move on to the question of how to share the Ubuntu folder.

Samba setup on Ubuntu 16.04

Let's start as usual with the installation. Installing Samba Ubuntu along with all the necessary components is done with the command:

sudo apt-get install -y samba samba-common python-glade2 system-config-samba

When everything is installed, you can proceed to the configuration. First, back up the original Samba configuration file:

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bak

After creating a backup, create your configuration file with this command:

sudo vi /etc/samba/smb.conf

First, let's specify the global file server settings. To do this, insert the following lines into the file:


workgroup = WORKGROUP

netbios name = Ubuntu Share
dns proxy = no

max log size = 1000
passdb backend = tdbsam
unix password sync = yes

pam password change = yes
map to guest = bad user
usershare allow guests = yes

Let's take a closer look at what these lines mean.

  • workgroup- the working group, as already mentioned, should be the same on all machines
  • netbios name- the name of the computer that will be displayed in Windows;
  • log file- the address of the file where error messages and other information will be stored;
  • security- by default, perform user-level authentication;
  • name resolve order- the order of resolution of IP addresses by NetBIOS name. bcast - means to send a broadcast request to the local network. If all computers between which you plan to interact are in the same network, this option is optimal;
  • passdb backend- a way of storing user passwords;
  • unix password sync- synchronization of samba user passwords with local Unix passwords;
  • map to guest- indicates when the user will be granted guest access. There are three values ​​available - never- never, bad user- when no such user exists, bad password- when the password is entered incorrectly,

When you've finished creating the configuration file, let's move on to the question of how to share the Ubuntu folder for Windows.

Share Ubuntu folder

First, let's create a shared folder available to everyone. That is, with anonymous access, without samba authorization.

Create a folder to which we will open access, for example:

sudo mkdir -p / samba / allaccess

After the folder is created, you need to set the correct access rights for it. The following commands allow everyone to access the folder and make the owner nobody:

cd / samba
sudo chmod -R 0755 allaccess
sudo chown -R nobody: nogroup allaccess /

The next step is to describe the allaccess folder in the samba configuration file:


path = / samba / allaccess
browsable = yes
writable = yes
guest ok = yes
read only = no

Your config file should now look like this:


workgroup = WORKGROUP
server string =% h server (Samba, Ubuntu)
netbios name = Ubuntu Share
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
passdb backend = tdbsam
unix password sync = yes
passwd program = / usr / bin / passwd% u
pam password change = yes
map to guest = bad user
usershare allow guests = yes
#==============
path = / samba / allaccess
browsable = yes
writable = yes
guest ok = yes
read only = no

Let's take a closer look at the options that were used here:

  • path- the path to the folder you want to share;
  • browsable- whether the folder will be displayed in the list of available shares;
  • writable- whether the folder will be available for writing;
  • read only- the folder is read-only;
  • guest ok, public- whether guest access will be allowed;
  • only guest- if set to yes, then the folder will be available only to guests;
  • hosts allow- ip addresses from which you can get access to this server;
  • valid users- by default, all users can log in, if a list of users is passed in this parameter, then only they can log in;
  • create mask- mask of rights for created files.

Restart the Samba server to apply the changes:

sudo systemctl restart samba

Samba setup for Ubuntu 16.04 for anonymous access is now complete. Now you can check the availability of the allaccess shared folder from Windows, to do this press Win + R and run:

\\ srvr1 \ allaccess

You will see our folder. If you don't see it, check the configuration again. The folder can be accessed without samba authorization. Setting up Samba shares with unauthorized access is now complete.

You can also connect to this server from Linux using Nautilus, for this you just need to type the address smb: // server ip, under other places:

Protected Sharing Ubuntu Folder

To share a folder for Windows Ubuntu, to which only users from a specific group will have access, create a separate folder and describe it in the Samba configuration file in Ubuntu.

First, create a folder:

sudo mkdir -p / samba / allaccess / secured

Create a group:

sudo addgroup securedgroup

Setting up the rights:

cd / samba / allaccess
$ sudo chown -R richard: securedgroup secured
$ sudo chmod -R 0770 secured /

The last step is to add the settings to the samba config file:

sudo vi /etc/samba/smb.conf


path = / samba / allaccess / secured
valid users = @securedgroup
guest ok = no
writable = yes
browsable = yes

Restart the Samba server. Now only users of the securegroup can access the shared folder in Ubuntu.

To check how it works, let's add the user richard to our group:

sudo usermod -a -G securedgroup richard

Linux is a great operating system, but we’re not going to get away from Windows, and neither is it from us. Windows will always surround us - whether it is a home, corporate network or an Internet cafe. We constantly have to exchange documents with Windows computers - after all, not all users prefer to work in Linux. Having at its disposal a server on Linux , in any case, there will be a need to interact with Windows computers, so we will talk about connecting Linux to the Microsoft network.

Installing Samba

To install Samba, we need to install the samba and samba-client packages. It is also advisable to install the smbfs package. In addition, the system will update the samba-common package, which may already be installed on the system. All my manipulations will be carried out on Ubuntu 10.04, the main difference from other distributions is the installation method. For Ubuntu through the console, this way:

$ sudo apt - get install samba

Or using the Synaptic package manager, which I did, this option turned out to be more convenient for me, since I could select from the list those packages that I needed, these were:

    samba

    smbclient

    samba-common

If you've used a different Linux distribution in the past, you're probably familiar with the LinNeighborhood program. It is a graphical program that allows you to view Windows network resources. There is no need for it in Ubuntu. First, the standard GNOME tools allow you to browse Windows networks. And secondly, for the sake of interest, the LinNeighborhood program was installed from one of the Ubuntu repositories. It turned out that this program, found by Synaptic, is not usable at all (localization issues). Well, okay, it makes sense to figure it out if there are excellent standard tools that already work.

Basic Samba setup

At this stage, we will assume that the utility is installed. The main Samba configuration file is /etc/samba/smb.conf. You need to open it and change several parameters. The first one is workgroup - it sets the name (of your choice) of the NT workgroup or domain:

WORKGROUP = MyHomeGroup

You can also set the comment parameter - this is a description of your computer:

comment = My Linux computer

Set the security parameter. If the network is client / server, then you need to select the server parameter, and ifpeer-to-peer network (i.e. a network without a dedicated server), then you need to select user or share:

security = share

Set the name of the guest account like this:

guest account = guest

You also need to configure encodings:

client code page = 866

character set = utf8

To make Samba run faster, set the following options:

socket options = TCP_NO DELAY SO_RCVBUF = 8192 SO_SNDBUF = 8192

dns proxy = no

The interfaces parameter specifies the interfaces on which the Samba service should run. It is necessary to specify the interfaces that connect our machine to Windows networks:

interfaces = 192.168.0.22/24

Configuring Shares

Now it remains to configure the resources that we want to provide for general use, this is the [ public].

# general directory

comment = Public Directory

# path

path = / var / samba

# not only reading

read only = no

# allow writing

writable = yes

# allow guest access

guest ok = yes

# allow viewing directory contents

browseable = yes

In this case, the / var / samba directory will be a shared resource on our computer (you need to create it, since there is no such directory on the system by default). Other users will be able to write their files to it (read only = no, writeable = yes), of course, they will be able to read them (browseable = yes). You do not need to check the username and password to access the resource (guest ok = yes) - the so-called guest access is used. The comment "Public Directory" will be seen by other users of the Windows network when viewing the resources of our computer.

If there is a need to provide general access ("share") to the user's home directories, then go to the section ;. Uncomment all lines commented out with a semicolon before the line ;. T . e. you should get the following:

comment = Home Directories

browseable = no

valid users =% S

writable = no

create mask = 0600

directory mask = 0700

For now, custom directories will not be visible in the list of shared resources, you can refer to them at \\ server \ username ... For example, \\ server \ petya. If you want the user resources to be browseable, then set the browseable parameter to yes:

browseable = yes

After all the changes, save the configuration file and start (or restart - restart) Samba:

$ sudo /etc/init.d/samba start

Viewing Windows Network Resources

You can view the resources of the Windows network using the smbclient program, but it works in text mode, so it is not very convenient to use. It is much more convenient to use a file browser to browse network resources. This can be done using the menu Transition | Connect to server ...

Samba Optimization Secrets

Now let's talk about how to make Samba run a little faster. If you open the smb.conf configuration file, you will find the wide links parameter in it. Never install it in no ! This will significantly reduce the performance of Samba. On the contrary, you need to set it to yes (if the wide links parameter was disabled before), which will significantly increase performance.

The wide links parameter determines how Samba follows symbolic links. If wide links = no, then Samba will not follow symbolic links outside the exported area. Samba first follows a symbolic link and then executes a so-called directory path lookup (a system call that determines where the link ended). This operation implies 6 more system calls than if wide links = yes. Considering that there are a lot of such operations being done, disabling wide links decreases Samba performance by about 30%.

Implementation of network protocols Server Message Block (SMB) and Common Internet File System (CIFS)... The main purpose is to share files and printers between Linux and Windows systems.

Samba consists of several daemons that run in the background and provide services and a number of command line tools for interacting with Windows services:

  • smbd- a daemon that is an SMB server for file and print services;
  • nmbd- a daemon that provides NetBIOS naming services;
  • smblient- the utility provides command line access to SMB resources. It also allows you to get lists of shared resources on remote servers and view your network environment;
  • smb.conf- configuration file containing settings for all Samba tools;

List of ports used by Samba

  • share- This security mode emulates the authentication method used by Windows 9x / Windows Me operating systems. In this mode, usernames are ignored and passwords are assigned to shares. In this mode, Samba tries to use a client-supplied password that can be used by different users.
  • user* - This security mode is set by default and uses a username and password for authentication, as is usually done in Linux. In most cases on modern operating systems, passwords are stored in an encrypted database that only Samba uses.
  • server- This security mode is used when Samba needs to authenticate against another server. For clients, this mode looks the same as user-level authentication (user mode), but in fact, to perform authentication, Samba contacts the server specified in the password server parameter.
  • domain- using this security mode, you can fully join a Windows domain; to clients it looks the same as user-level authentication. Unlike server-level authentication, domain-based authentication uses more secure domain-level password exchange. Full domain joins require additional commands on the Samba system and possibly on a domain controller.
  • ads- This security mode is similar to the domain authentication method, but requires an Active Directory Domain Services domain controller.

Complete list of parameters Samba available in manpages.

Above was an example with access for a shared directory. Let's consider another example with a private directory, which can be accessed only by login and password.

Create a group and add a user to it

Sudo groupadd smbgrp sudo usermod -a -G smbgrp proft

Create a directory for the user and set the rights

Sudo mkdir -p / srv / samba / proft sudo chown -R proft: smbgrp / srv / samba / proft sudo chmod -R 0770 / srv / samba / proft

Create a samba user

Sudo smbpasswd -a proft

Add a new resource to /etc/samba/smb.conf

Path = / srv / samba / proft valid users = @smbgrp guest ok = no writable = yes browsable = yes

Let's restart the server

Sudo systemctl restart smbd

An example of configuring a resource that has symlink to the user's folder ( / srv / samba / media / video » / home / proft / video)

Path = / srv / samba / media guest ok = yes read only = yes browsable = yes force user = proft

Client setup

Viewing Shared Computer Resources

Smbclient -L 192.168.24.101 -U%

Another way to connect for anonymous user with command line

Smbclient -U nobody //192.168.24.101/public ls

If the server is configured with a higher security level, you may need to pass the username or domain name using the -W and -U options, respectively.

Smbclient -L 192.168.24.101 -U proft -W WORKGROUP

Mounting a samba resource

# create mount point mkdir -p ~ / shares / public # mount resource # for anonymous user nobody mount -t cifs //192.168.24.101/public / home / proft / shares / public -o user =, nobody password =, workgroup = WORKGROUP, ip = 192.168.24.101, utf8 # for user proft mount -t cifs //192.168.24.101/public / home / proft / shares / public -o user = proft, password = 1, workgroup = WORKGROUP, ip = 192.168. 24.101, utf8

Better yet, store passwords in a separate file.

# sudo vim / etc / samba / sambacreds username = proft password = 1 username = noboy password =

Let's set access rights 0600

Sudo chmod 0600 / etc / samba / sambacreds

New line to mount

Mount -t cifs //192.168.24.101/public / home / proft / shares / public -o user = proft, credentials = / etc / samba / sambacreds, workgroup = WORKGROUP, ip = 192.168.24.101

And an example for / etc / fstab

//192.168.24.101/public / home / proft / shares / public cifs noauto, username = proft, credentials = / etc / samba / sambacreds, workgroup = WORKGROUP, ip = 192.168.24.101 0 0

You can open a resource in the file manager Nautilus / Nemo / etc using this path smb: //192.268.24.101.

If Nemo writes Nemo cannot handle "smb" locations. means there is not enough package gvfs-smb.

Server access from Windows and Android client

Under Windows, you can find out the workgroup from the console using

Net config workstation

You can open resources on a remote machine by typing the UNC address in the Explorer line or in Run (Start - Run): \192.168.24.101 .

For Android, you can connect to the server using ES File Explorer, on the Network tab, add a server, simply by IP (without specifying a scheme, smb). Then you can open shared resources. For statistics: HDRIP-movie runs without slowdown.

Additional reading

Now it is quite common to find computers running Linux and Windows on the same local network. The reasons for this symbiosis can be different: for example, the owners of Internet cafes did not have enough funds to purchase a licensed OS for all computers, or the system administrator was simply attracted by the positive aspects of Linux. The popularity of Microsoft operating systems is largely determined by the client software for Windows. It's no secret that this software sector is highly developed. Many companies have made serious efforts to this and have created really good, and most importantly, easy-to-use programs that even an ordinary user can easily master. But as a server, the position of Windows is no longer so unambiguous. A server running Unix is ​​traditionally distinguished by reliability, stability in operation, security and often lower requirements for system resources. But in any case, simply by connecting computers with different software platforms to the network, we will not get the expected result. The whole problem is that these two systems use different principles of organizing network resources, which are incompatible with each other.
Since there is no need to wait for Microsoft's grace, and Windows is unlikely to learn how to work with the Unix Network File System (NFS) by standard means, and to be honest, I don’t know third-party programs, the most popular way is to try to teach Unix to "pretend" it would be Windows NT.

Interaction in a network of computers running Windows is based on the use of the protocol SMB (Server Message Block)- blocks of server messages. It provides the performance of all the tasks necessary in these cases for opening and closing, reading and writing, searching for files, creating and deleting directories, setting a print job and deleting it from there. All the actions necessary for this are implemented in Unix-like operating systems using the package SAMBA... Its capabilities can be conditionally divided into two categories: provision of resources (which means access to the printer system and files) for Windows clients and access to client resources. That is, a Linux computer can act as both a server and a client. To begin with, let's consider the SAMBA server option.

What should SAMBA provide for normal operation in a network of Windows machines? First, access control, which can be implemented either at the share level, when a password is assigned to any resource on the network and the corresponding rules of use (for example, "read-only"), while the username does not have absolutely no value; or a more perfect and flexible organization at the user level, when an account is created for each user, which, in addition to the name and password, contains all the necessary information about the access rights to the resource. Before accessing the required resource, each user is authenticated, after which he is granted the rights according to the accounts. Secondly, it is necessary to emulate the access rights defined by the file system. The thing is that the systems under consideration have different access rights to files and directories on the disk. Traditionally, Unix has three categories of file users: owner, group and rest (other)... Each of these subjects can be provided with read permissions, write and execute... In Windows NT, the access system is somewhat more flexible, access is granted to several groups or users, and the corresponding access rights are determined separately for each subject. Therefore, it is impossible to fully emulate NTFS access rights using SAMBA.

With clients running Windows 9x, the situation is different. Since the days of DOS's grandfather, due to the fact that the system is single-user and there could be no question of any users, let alone groups, only four attributes have been defined for the FAT file system - read only, system, archive and hidden... Plus, in Windows, unlike Unix, the file extension has a special meaning - those that are intended to be executed have the extensions .exe, .com, or .bat. When copying files from Unix machines to computers running Windows, the attributes are set as follows:

only for reading- reading, writing for the owner;

archival- execution for the owner;

systemic- execution for the group;

hidden - execution for the group.

A network of Windows machines can be organized as a workgroup, when computers are independent from each other and each has its own database of passwords and logins with its own security policy, as well as an NT domain. The entire base for user and computer authentication is managed Primary Domain Controler (PDC), i.e. centralized. Samba allows you to restrict access at all of these levels and acts as a "master browser" in the context of a workgroup or domain controller.

We have dealt with general organizational issues. Let's now look specifically at the implementation and configuration of a SAMBA server in Linux. For the Samba server to work, two daemons must be running: smbd which provides a print and file sharing service for Samba clients (such as Windows of all stripes), and nmbd that provides NetBIOS naming services (it can also be used to query other naming service daemons). The protocol is used to access clients TCP / IP... Typically, Samba is installed along with the Linux distribution. How to check? Just give the command:

$ whereis samba

and you should get something like this:

Samba: / usr / sbin / samba / etc / samba /usr/share/man/man7/samba.7.gz

If it is not included in the standard distribution, then welcome to ftp://ftp.samba.org/pub/samba/samba-latest.tar.gz or to almost any server with Linux programs. The package is easy to install, so to save space, we will assume that you have it installed. Now let's check if the daemon is running:

$ ps -aux | grep smbd root 1122 0.0 0.6 4440 380? S 16:36 0:00 smbd -D

As you can see, I have it already started. If you do not have it, and you want it to start when the system boots, then in Linux Mandrake, for example, check the required item in DrakConfstarting services or in Red Hat Сontrol-panelServise Configuration this is usually enough. Or start manually: ./etc/rc.d/init.d/smb start. The only Samba configuration file is called smb.conf and is usually found in the / etc / directory (although in AltLinux, for example, it is located in the / etc / samba directory). The SAMBA service reads it every 60 seconds, so the changes made to the configuration take effect without reboot, but do not affect the connections already established.

This is why I love Linux, because the configuration files are plain text (besides, they are well commented inside), and in order to use most of the parameters, you just need to uncomment the corresponding line. The smb.conf file is no exception. It consists of named sections starting with the section name, enclosed in square brackets. Each section contains a number of parameters in the form key = value. The configuration file contains four special sections:,, and separate resources (shares). As the name suggests, the section contains the most general characteristics that will be applied everywhere, but which, however, can then be redefined in the sections for individual resources. Several of the options in this section are relevant to configuring the Samba client.

Values ​​of typical section parameters global:

Workgroup = group_name # workgroup name on the Windows network netbios name = server name on the network server string = comment that is visible in the network view properties window guest ok = yes # guest login permission (guest ok = no - guest login is denied) guest account = nobody # the name under which the guest logon is allowed security = user # Access level. user - at the user level, security = share - username and password based authentication. When storing the password database on another SMB server, the values ​​security = server and password server = name_server_NT are used. If the server is a member of the domain, the value security = domain is used, the password for access is specified in the file specified with the smb option passwd file = / path / to / file.

In addition, when registering, you can use encrypted and plain-text passwords... The latter are used in old Windows (Windows for Workgroups, Windows 95 (OSR2), all versions of Windows NT 3.x, Windows NT 4 (up to Service Pack 3)). To enable the option to use an encrypted password, use the encrypt password = yes option. Please pay special attention to this option. Older Linux distributions that were created in the era of Windows 95 (and with an older version of Samba) have password encryption disabled by default, and samba is up to version 2.0 does not support this mode at all (by the way, this option and similar ones - those that do not relate to access to specific resources - are also used in the client).

To display Russian filenames correctly, you need the following options: client code page = 866 and character set = koi8-r. Distributions with good localization, for example, derivatives from Mandrake and Russian, already have this line, sometimes it is enough to simply uncomment it, but in most others you have to add it yourself.

The interfaces = 192.168.0.1/24 option specifies in which network (interface) the program should work if the server is connected to several networks at once. If you set the bind interfaces only = yes parameter, the server will only respond to requests from these networks.

hosts allow = 192.168.1. 192.168.2. 127. - defines clients for whom access to the service is allowed.

In the global section, it is possible to use various variables for more flexible configuration of the server operation. After the connection is established, real values ​​are substituted for them. For example, in the directive log file = /var/log/samba/%m.log, the% m parameter helps to define a separate log file for each client machine. The most common variables used in the global section are:

% a - OS architecture on the client machine (possible values ​​- Win95, Win NT, UNKNOWN, etc.);

% m is the NetBIOS name of the client computer;

% L - SAMBA server NetBIOS name;

% v - SAMBA version;

% I is the IP address of the client's computer;

% T - date and time;

% u - the name of the user working with the service;

% H is the home directory of user% u.

Also, for more flexible customization, the include directive is used using the above variables. For example: include = /etc/samba/smb.conf.%m - now, when requesting from the computer sales if the file /etc/samba/smb.conf.sales is present, the configuration will be taken from this file. If there is no separate file for some machine, then a common file is used to work with it.

There is also an interesting opportunity creating a virtual server... The netbios aliases parameter is used for this:

Netbios aliases = sales accounting admin

Now we order Samba to use its own configuration file for each virtual server:

Include = /etc/samba/smb.conf.%L

Three servers will be visible in the network browser window: sales, accounting, admin.

Enabling the preserve case and short preserve case options force the server to store all input in a case-sensitive manner (in Windows, case does not matter, in all Unixes it is vice versa).

The section allows users to connect to their working directories without explicitly describing them. When a client requests his / her directory // sambaserver / sergej, the machine looks for the corresponding description in the file and if it does not find it, then looks for the presence of this section. If the key exists, the password file is scanned to find the working directory of the requesting user and, if found, makes it available to the user.

A typical description for this section looks like this:

Comment = Home Directories # the comment that is visible in the network properties window browseable = no # determines whether to display the resource in the browse list. writable = yes # allows (no - disallows) writing to the home directory create mode = 0750 # permissions for newly created files directory mode = 0775 # also, but only for directories

After configuring the default settings, you can create network shares that can be accessed by a specific user or group of users. Such a resource is created from an existing directory, for this we write in the file:

Comment = Public Stuff path = / home / samba public = yes writable = no printable = no write list = administrator, @sales

The path parameter points to the directory where the resource is located; the public parameter indicates whether the guest can use the resource, and printable indicates whether the given resource can be used for printing. The write list parameter allows you to define the users who are allowed to write to the resource regardless of the writable value (in this example, the user administrator and the sales group). It is also possible to use the opposite list - read list. If there is a need to hide some files, then on Unix / Linux for this, the file name must start with a dot (the hide dot files parameter, which controls the display of hidden files, by default is yes). In addition, it is possible to set templates for names of hidden files, for which the hide files parameter is used. Each pattern begins and ends with a forward slash (/) and can contain characters used in regular expressions. For example: hide files = /*.log/??.tmp/. Such tricks are bypassed for Windows users just by setting the "Show hidden and system files" mode in Explorer. Use the veto files and delete veto files parameters to reliably restrict the accessibility (ability to delete) of a file (directory).

With CD drives, the situation is somewhat more complicated. The thing is that in Unix-like systems, the concept of a disk is absent as such, and in order to access the desired device, it must first be mounted in a directory tree (# mount -t iso9660 / dev / cdrom / mnt / cdrom) , and after use, so as not to destroy the file system, it must be unmounted (# umount / dev / cdrom), otherwise the device will simply not give up the disk. If you have a daemon running on your server autofs, then the problem can be solved simply. To automatically unmount a device that has not been used for some time, set the desired value for the timeout parameter in the /etc/auto.master file. For instance:

/ mnt / auto / etc / --timeout = 5

(a similar line is already there, you just need to uncomment it). Then set the options for the appropriate device in the /etc/auto.tab file:

Cdrom -fstype = auto, ro: / dev / cdrom

After all this, we write the following lines in /etc/smb.conf to make this resource available:

Path = / mnt / cdrom writable = no

The second option is to use the preexec and postexec directives, which indicate which commands should be executed when accessing a resource and after disconnecting from it (these parameters can be specified for any resource and even in the global section, which opens up great opportunities).

Path = / mnt / cdrom read only = yes root preexec = mount / mnt / cdrom # only root can mount the resource root postexec = umount / mnt / cdrom # naturally, these mount points must be described in the / etc / fstab file, otherwise you must also specify the rest of the data.

Now, when accessing a resource, the CD-ROM is automatically mounted, and sometimes unmounted. The whole problem is that the decision to close the resource must be made by the server - clients, as a rule, do not notify about this. But usually this happens because the resource is simultaneously used by several users at once or an open file is left on the same computer on this resource (Device busy). Therefore, the CD-ROM will not automatically unmount, the only acceptable way to free the resource is to look with the utility smbstatus the number of the process using this resource and kill it with the # kill pid_number command (or kill -s HUP pid_number).

With the required configuration set up, now we will create user accounts (except for the guest login with minimal privileges nobody). To identify SAMBA users, the / etc / samba / smbpasswd file is used, which contains usernames and encrypted passwords. Since the encryption mechanism in networks of Windows machines is not compatible with standard Unix mechanisms, a separate utility is used to fill in the password file - smbpasswd.

# useradd -s / bin / false -d / home / samba / sergej -g sales sergej # smbpasswd -a sergej # smbpasswd -e sergej

This example adds a new user sergej belonging to the group sales, with a dummy shell (the options are / sbin / nologin, / dev / null) and the home directory / home / samba / sergej. Then we create a password for the user sergej and, as the last step, enable access to the user. it is disabled by default. An interesting point that can be confusing at times. The fact is that when a computer with Windows NT / 2000 is connected to the SAMBA server, the user is prompted to enter, as expected, a username and password, and if a computer with Windows 9x / Me is used for access, then the user is prompted to enter only the password, and the login is generated automatically based on the registration name.

It is also possible to map multiple Windows users to a single Linux / Unix user. To do this, a mapping file /etc/smbusers.map is created, in which each mapping is set on a separate line:

Linux_user = user_win1 user_win2 user_winN

In the section add the line username map = /etc/smbusers.map. In this case, the Windows user must be logged in with the password of the user with whom he is associated.

Using SAMBA, you can organize the ability to network printing from computers running Windows (if a separate print server is planned, then a machine based on a 486 processor may be sufficient for this).

To do this, write the following lines in the section:

Printcap name = / etc / printcap # file describing printers connected to the system load printers = yes # indicates the need for automatic inclusion in the list of network resources printing = lprng # printing system (for Linux, bsd can still be used).

Path = / var / spool / samba # points to the directory where print jobs are placed browseable = yes printable = yes read only = yes

After creating the file, test it with the utility testparm... Unfortunately, with the help of this program you can detect only syntax errors, not logical ones, so there is no guarantee that the services described in the file will work correctly (during testing, all settings will be displayed, even those that are installed by default - therefore, carefully review result). But if the program does not swear, you can hope that the file will be loaded without problems at startup. The correct operation of the printers listed in the / etc / printcap file with the SAMBA server can be checked using the utility testprns... Plus, don't forget about the .log files: if you have problems, you can sometimes find a solution there.

Now a little about the good. Configuring Samba is a rather complicated procedure, but the distribution comes with a Web-based administration tool called swat(Samba Web Administration Tool,). Swat is launched as a service or using the Apache server and is intended for editing the smb.conf file, as well as for checking the status, starting and stopping Samba daemons, and changing user passwords. For it to work as a service, the swat 901 / tcp line must be present in the / etc / services file, and swat stream tcp nowait. 400 root / usr / local / samba / bin / swat swat in the /etc/inetd.conf file (this is if a network daemon is used inetd usually in older distributions; modern distributions use a more secure option - xinetd). To use swat in the /etc/xinet.d directory, create a swat file with the following content:

Service swat (disable = no port = 901 socket_type = stream wait = no only_from = 127.0.0.1 # this is a line to run only from the local machine user = root server = / usr / sbin / swat log_on_failure + = USERID)

Now to run Swat in a browser window, enter:

Http: // localhost: 901

But before that, be sure to create a user admin as described above. And never run the SAMBA service as root.

After all the changes in the smb.conf file, you sometimes need to restart the daemon:

Smb: /etc/rc.d/init.d/smb restart

If, after all the above steps, it was still not possible to organize access to SAMBA resources, then such utilities as ping(to check the availability of a node in the network), nmblookup(to query for NetBIOS names), or as a last resort tcpdump... And do not forget about the permissions, because by assigning the directory / gde / to / w / glubine to the user, you will give him the ability to read (execute permission) and the previous directories.

Now let's talk about using the Samba client, because we (Linux users) also want to work with Windows network resources. In order to find out what resources are available, you must enter the command / usr / bin / smbclient -L host_name. The program will ask for a password, in response to which in most cases it is enough to press Enter. Now, to connect to the required resource, enter the computer name and the required resource. For instance:

# / usr / bin / smbclient \\ Alex \ Sound

(here we are trying to connect to the Sound folder on Alex's computer). As a result, if the command is entered correctly and such a network resource exists, you should receive a password prompt. Enter it or press Enter if no password is required to access. In response, you will receive a samba client prompt: smb:>. In the future, work is done by a set of commands with which you can perform all the necessary operations for working with files (copying, creating, moving, etc.). For help, enter smb:> help. This mode is somewhat inconvenient, therefore, in most cases, use the module smbfs which is part of samba; but on older distributions, the kernel can be built without smbfs support, in which case it will have to be rebuilt. To mount the required resource, type something like this:

Mount -t smbfs -o username = user, password = 123456, iocharset = koi8-r, codepage = 866 // alex / sound / mnt / sound.

If you do not specify a username and password, the system itself will ask you for it. Do not forget that by looking at the ~ HOME / .bash_history file, you can use the commands that you typed to find out the password. One more subtlety: if the smbclient program correctly displays files with Russian names, then the smbfs module sometimes pays absolutely no attention to another encoding, even if you specify it explicitly. They say it can be fixed with a patch, but I haven't found one for my Red Hat yet.

If you want the SMB share to be mounted automatically at system startup, add a line like this to the / etc / fstab file:

//[email protected]/ sound / mnt / alex / sound smbfs rw, noauto 0 0.

In this example, on behalf of the user guest(if the resource supports this user and if this user has access only by password, then do not worry: they will certainly ask you) the sound network resource on the alex computer is mounted in the / mnt / alex / sound folder with the ability to write to this directory. By the way, the Samba client perfectly sees hidden network resources, i.e. those whose network name ends with a $.

As you can see, you have to work with the command line, which causes quiet horror for the modern user. And here the world of OpenSource went to meet him - many utilities have been created that allow you to work with Samba resources in a more familiar way, by clicking buttons in graphical shells. The most popular program included in the Mandrake and derivatives distributions, as well as Debian - gnomba... In any case, it can be found on most servers with software for Linux (I saw it at ftp://ftp.altlinux.ru/ for sure). This utility allows you to view the available network resources () and, if necessary, mount to the desired directory, while the option of mounting with the indication of the login and password for those resources that require this is possible. It is possible to start the file manager when mounting (by default gmc), creating directories for mounted resources, setting the option for automatic scanning at program startup (possibly using the default SMB protocol) and scanning by IP addresses (planned using the WINS protocol). For reasons I have not clarified, in some distributions when scanning using the SMB protocol, network resources were not displayed, so I always use the second method, since it works flawlessly, you just need to set a range of IP addresses for scanning (if you know). In order to display the correct Russian file names, do not forget to install the koi8-r fonts in the tab Options> Font selection and also check the lines indicating the Cyrillic encoding in the smb.conf file (see above).

If gnomba can only mount and unmount resources, then the program xsmbrowser also allows you to enter them as folders on the local computer (). True, I have not yet been able to make this program understand files with Russian names, but there are also positive aspects: when this program is running, all mount commands and various network requests are displayed on the console, which allows you to understand them well. The KDE developers have also tried: through Preferences> Information utility available Samba Status, which displays all connections to / from the local computer, at the same time is a convenient means of viewing .log files. The utility provides similar information. komba which can be found at http://linux.tucows.com/ ().

As much as I would like to tell you more, but a magazine is a magazine - you can't fit everything. Further, the ubiquitous man and info will come to your aid. Also, all the necessary help information can be obtained from the SWAT utility, in addition, in Red Hat 7.3 there was a book Using Samba Robert "a Eckstein" a(English language - bad, completely free - good: / usr / share / swat / using_samba), also available from SWAT (). Additional documentation, FAQs, and sample configuration files can be found in the / usr / share / doc / samba directory. In various forums, you can find quite conflicting opinions about the work of Samba, from extremely negative to complete enthusiasm. Personally, I am on the side of the supporters of this Windows NT emulator, besides, according to the test results with the same hardware, the Samba server shows performance about 25-30% higher than a computer running a Microsoft system. Good luck.







2021 gtavrl.ru.