Creating a home network using Samba for devices running Windows, Linux, Android OS. Samba and Windows File Server for Windows Network Folder Sharing Ubuntu


Linux is an excellent operating system, but we can’t get away from Windows and neither can it from us. Windows will always surround us - be it at home, on a corporate network or on an Internet cafe. We constantly have to exchange documents with Windows computers - after all, not all users prefer to work in Linux. Having at your 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 differences from other distributions are the installation method. For Ubuntu via the console, like this:

$ sudo apt - get install samba

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

    samba

    smbclient

    samba-common

If you've ever used another Linux distribution, you're probably familiar with the LinNeighborhood program. This is a graphical program that allows you to view Windows network resources. There is no need for it in Ubuntu. Firstly, standard GNOME tools allow you to browse Windows networks. And secondly, just for fun, I installed the LinNeighborhood program from one of the Ubuntu repositories. It turned out that this program, found by Synaptic, is not usable at all (problems with localization). 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. Samba's main configuration file is /etc/samba/smb.conf. You need to open it and change several parameters. The first one is workgroup - it specifies the name (of your choice) of the workgroup or NT 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 guest account name like this:

guest account = guest

You also need to configure the encodings:

client code page = 866

character set = utf8

To make Samba work 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

Setting Up Shares

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

# shared 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 directory contents to be viewed

browseable = yes

In this case, the shared resource on our computer will be the /var/samba directory (it needs to be created, since there is no such directory on the system by default). Other users will be able to write their files into it (read only=no, writeable=yes), and naturally, they will be able to read them (browseable=yes). Verifying the username and password to access the resource is not necessary (guest ok=yes) - so-called guest access is used. The “Public Directory” comment will be seen by other Windows network users when viewing the resources of our computer.

If there is a need to provide general access (“share”) to users’ home directories, then go to the section;. Uncomment all lines commented out with a semicolon before the line;. T . e. it should look like this:

comment = Home Directories

browseable = no

valid users = %S

writable = no

create mask = 0600

directory mask = 0700

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

browseable = yes

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

$ sudo /etc/init.d/samba start

Viewing Windows network resources

You can view Windows network resources using the smbclient program, but it works in text mode, so it is not entirely convenient to use. It is much more convenient to use a file browser to view network resources. You can do this using the menu Transition | Connect to server...

Samba optimization secrets

Now let's talk about how to make Samba work 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 Samba performance. On the contrary, you need to set it to yes (if the wide links parameter was disabled before), which will significantly improve performance.

The wide links parameter determines how Samba will follow symbolic links. If wide links=no, then Samba will not follow symbolic links outside the exported scope. Samba first follows the symbolic link and then performs what is called a directory path lookup (a system call that determines where the link ends). This operation involves 6 more system calls than if wide links=yes. Considering that there are a lot of similar operations being done, disabling wide links reduces Samba performance by approximately 30%.

The main Samba configuration file is /etc/samba/smb.conf. The initial configuration file has a significant number of comments to document the various configuration directives.

Not all possible options are included in the default settings file. See manual man smb.conf or Samba FAQ for more details.

1. First change the following key/value pairs in the section file /etc/samba/smb.conf:

Workgroup = EXAMPLE ... security = user

Parameter security is located much lower in the section and is commented out by default. Also replace EXAMPLE to something more appropriate to your surroundings.

2. Create a new section at the end of the file or uncomment one of the examples for the directory that you want to share:

Comment = Ubuntu File Server Share path = /srv/samba/share browsable = yes guest ok = yes read only = no create mask = 0755

    comment: A short description of the shared resource. Used for your convenience.

    path: path to the shared directory.

    This example uses /srv/samba/sharename because, according to the File System Hierarchy Standard (FHS), the /srv directory is where all data related to a given site should reside. Technically, a Samba share can be placed anywhere on the file system where file access restrictions allow, but following standards is recommended.

    browsable: Allows Windows clients to view the contents of a shared directory using Windows Explorer.

    guest ok: Allows clients to connect to the shared resource without providing a password.

    read only: Determines whether the resource is accessible with read-only or write privileges. Write privileges are only available when you specify no, as shown in this example. If the value yes, then access to the resource will be read-only.

    create mask: Defines what access rights will be set for new files created.

3. Now that Samba is configured, you need to create a directory and set permissions on it. Enter in terminal:

Sudo mkdir -p /srv/samba/share sudo chown nobody.nogroup /srv/samba/share/

parameter -p tells mkdir to create a complete directory tree if it doesn't exist.

4. Finally, restart samba services to apply the new settings:

Sudo restart smbd sudo restart nmbd

You can now search the Ubuntu file server using the Windows client and browse its shared directories. If your client does not show your shares automatically, try accessing your server by its IP address, for example, \\192.168.1.1, from a Windows Explorer window. To check that everything works, try creating a directory inside your share from Windows.

To create additional shares, create a new section in /etc/samba/smb.conf and restart Samba. Just make sure the shared directory is created and has the correct permissions.

Shared resource "" and the way /srv/samba/share- these are just examples. Set the resource name and directory name according to your environment. It is a good idea to use the name of the resource's directory on the file system as the name of the resource. In other words, the resource can be specified for the /srv/samba/qa directory.

In this tutorial we are going to learn how to install and configure Samba server on Ubuntu 16.04. Samba is a free and open source implementation of the SMB/CIFS protocol for Unix and Linux that allows file and printer communication on Unix/ and Windows machines on a local network.

Samba is a software package, the two most important of which are:

  • smbd: Provides SMB/CIFS service (file and print sharing) and can also act as a Windows domain controller.
  • nmbd: Provides NetBIOS naming service

How to install Samba server on Ubuntu 16.04

Samba is included with most Linux distributions. To install Samba on , simply run:

Sudo apt install samba

The latest stable version available is 4.5.3, released on December 19, 2016. To check the version Samba , run

Sudo smbstatus

Sudo smbd --version

Example output:

Samba version 4.3.11-Ubuntu

To check if the Samba service is running, run the following commands.

Systemctl status smbd systemctl status nmbd

To start these two services, run the following commands:

Sudo systemctl start smbd sudo systemctl start nmbd

After launch, smbd will listen on port 139 and 445.

Editing a Configuration File

There's only one configuration file that needs to be edited: /etc/samba/smb.conf.

Sudo nano /etc/samba/smb.conf

In the section, make sure the value workgroup belong to a workgroup of Windows computers.

Workgroup = WORKGROUP

Scroll down to the bottom of the file. (In the nano text editor, press CTRL+W and then CTRL+V .) Include a new section as shown below. Replace username with the desired username.

Comment = Home Public Folder path = /home/username/ writable = yes valid users = username

Home Share is the name of the folder that will be displayed on the Windows network. A comment is a description of the shared folder. The next 3 lines indicate that only the specified user, valid users, has access to the /home/username/ directory, which is also writable. The above configuration will disable anonymous access.

Save and close the file, and then run the following command to check if there are syntax errors.

Testparm

Creating a user

Samba contains a default user as a security mode, meaning that clients must enter a username and password to access the shared folder. To add a user in Ubuntu, run the following command:

Sudo adduser username

You will be prompted to set a Unix password. Additionally, you need to set a separate Samba password for the user using the following command:

Sudo smbpasswd -a username

Now all that's left to do is restart the smbd daemon.

Sudo systemctl restart smbd

Samba access to shared folder from Windows

On a Windows computer that is on the same network, open File Explorer and click Network in the left pane. You will see a samba server. Double-click the shared folder and enter your username and password.

Samba access to share folder from Ubuntu computer

In File Manager, go to the Network tab in the left pane and select Windows Network.

Select the workgroup, Samba server, and shared folder, and then enter the Samba username and password.

Adding multiple users or groups

If multiple accounts need to gain access to a shared folder, then the authorized users must be changed, as shown below in the /etc/samba/smb.conf file.

Valid users = user1, user2, user3

Also use smbpasswd to set the Samba password for each of these users.

Sudo smbpasswd -a user1 sudo smbpasswd -a user2 sudo smbpasswd -a user3

To allow a group of users to access a shared folder, use the following configuration in /etc/samba/smb.conf.

Valid users = @sambashara

Create a group.

Sudo groupadd sambashare

Then add users to this group

Sudo gpasswd -a user1 sambashare sudo gpasswd -a user2 sambashare sudo gpasswd -a user3 sambashare

The group must have write permission to the shared folder, which can be achieved with the following two commands.

Set sambashare as the group owner of the shared folder:

Sudo chgrp sambashare /path/to/shared/folder -R

Grant write permission to the group.

Sudo chmod g+w /path/to/shared/folder/ -R

I hope this article helped you set up a Samba server on Ubuntu 16.04. As always, if you found this post helpful, please leave a comment.

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 services 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- a configuration file containing settings for all Samba tools;

List of ports used by Samba

  • share- This security mode emulates the authentication method used by the Windows 9x/Windows Me operating systems. In this mode, usernames are ignored and passwords are assigned to shares. In this mode, Samba attempts 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 is used only by Samba.
  • server- this security mode is used when it is necessary for Samba to perform authentication when accessing another server. For clients, this mode looks the same as user-level authentication (user mode), but Samba actually contacts the server specified in the password server parameter to perform authentication.
  • domain- using this security mode, you can fully join a Windows domain; For clients, this looks the same as user-level authentication. Unlike server-level authentication, domain authentication uses more secure password exchange at the domain level. To fully join a domain, you need to run additional commands on the Samba system and possibly on the domain controller.
  • ads- This security mode is similar to the domain authentication method, but requires an Active Directory Domain Services domain controller.

Full list of parameters Samba is in manpages.

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

Let's create a group and add a user to it

Sudo groupadd smbgrp sudo usermod -a -G smbgrp proft

Let's create a directory for the user and set rights

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

Let's 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 setting up a resource that contains 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

View your computer's shared resources

Smbclient -L 192.168.24.101 -U%

Another way to connect for an anonymous user with the command line

Smbclient -U nobody //192.168.24.101/public ls

If the server is configured with a higher level of security, 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 a mount point mkdir -p ~/shares/public # mount a 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

It's even better to store passwords in a separate file.

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

Set the access rights to 0600

Sudo chmod 0600 /etc/samba/sambacreds

New mount line

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 the resource in the Nautilus/Nemo/etc file manager using this path smb://192.268.24.101.

If Nemo writes Nemo cannot handle "smb" locations. it means the package is missing gvfs-smb.

Access to the server with 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 .

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

Additional reading







2024 gtavrl.ru.