Quick and easy samba setup. Samba File Server


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%.

This article will discuss creating a wireless local network for devices running various operating systems Windows, Linux, Android using Samba.

Nowadays, almost every apartment has a Wi-Fi network, and there is also a large number of different devices (laptops, smartphones, tablets, Android TV Box). In this regard, sooner or later there will be a need to combine all devices available for use into one home network in order to easily access all kinds of files from any gadget.

This is actually what will be discussed in this opus. So let's get started.

For network construction, we will use a ready-made solution called Samba. This is a package of free open source programs that allows you to connect to network drives, printers and other equipment on various operating systems using its own SMB/CIFS protocol.

The software consists of two parts - server and client. We will install the Samba server on one of the devices, which by definition will be the main one, and the Samba client on all the others.

Installing the Samba server

In my case, for the server device, I chose a laptop on which Windows 7 and Ubuntu Mate 16.04 were installed in parallel. Below we will consider in detail the process of installing and configuring Samba for both operating systems.

Setting up samba server under Linux

By default, Samba is not installed in Ubuntu, so you need to do so before moving on. As an option, in order not to subsequently edit the Samba configuration file through the terminal, we will install the Gadmin-Samba program, which includes, in addition to Samba server packages, a graphical interface.

To install, type in the terminal:

Sudo apt install gadmin-samba

Once the installation is complete, launch Gadmin Samba. The application interface is not Russified, but understanding the settings is quite simple.


There are a lot of settings in the program, but by and large, in our case we are interested in the “users” tab. Go to it and add a new user.


Click the “New user” button, enter the user name in the updated window, come up with a password, add it to the group (in order not to “invent the wheel”, indicate the existing one, namely “sambausers”) and set the home directory for the files. After that, click "Apply".


HD Videobox - new user

To apply the changes, restart the server using the “deactivate” and “activate” buttons, respectively, located in the upper left corner of the application window.


Don’t forget, also, to set access rights to “shared” folders for shared access. This can be done either through the terminal or through the graphical interface of the Nautilus file explorer.


Nautilus - changing permissions


Nautilus - File Write Permission

Setting up samba server on Windows

In the case of Windows, everything is much more prosaic, since Samba is used by default in this operating system.

In principle, you can use an existing account or enable guest access. Alternatively, you can create another account, the data of which will be used for network access

To create a new account, you need to go to the “control panel”, select “manage user accounts” and create a new account with a password.


Adding a new account

When creating a new user, you will need to select an account type, create a name and password.


At the last stage, you will need to set rights to view changes to “shared” folders. This can be done in standard Windows Explorer through the “properties” context menu item in relation to the folder you need.


"Sharing" a folder


Adding a user and changing folder permissions

After creating a new user, be sure to re-login to the current session for the changes to take effect.

Installing the Samba client on Android

To access the Samba server and, accordingly, network drives on devices running Android, I recommend using the Root Explorer application (link to download the full version without advertising at the end of the article).

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.

Samba is a program that allows you to access network drives on various operating systems using the SMB/CIFS protocol. It has client and server parts. It is free software, released under the GPL license.
Samba runs on most Unix-like systems, such as GNU/Linux, POSIX-compliant Solaris and Mac OS X Server, various BSD variants, OS/2, Windows. Samba is included in almost all GNU/Linux distributions, including, of course, Ubuntu.
Installation

To make a shared folder in Ubuntu Desktop, just right-click on the folder and select the “Publish Folder” menu item. There is no need to edit any configuration files. Everything described below applies only to manual configuration, for example, in the case of creating a file server.
To install, just open a terminal and enter:

sudo apt-get install samba

The application will be automatically downloaded and installed.

Settings

Using the terminal, we will make a backup copy of the initial configuration file:

Sudo cp /etc/samba/smb.conf(,.bak)

Now you can edit the settings file /etc/samba/smb.conf; to do this, open it in any text editor with superuser rights. For example, like this:

Sudo nano /etc/samba/smb.conf An example of configuring Samba as a standalone file server with authorization: ; Global server settings; General server settings; Computer name that will be displayed in the network environment netbios name = main-server server string = ; Client workgroup workgroup = WORKGROUP announce version = 5.0 socket options = TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192 passdb backend = tdbsam security = user null passwords = true ; File for user name aliases username map = /etc/samba/smbusers name resolve order = hosts wins bcast ; wins support is set to yes if your nmbd(8) in Samba is a WINS server. Do not set this parameter to yes unless you have multiple subnets and do not want your nmbd to act as a WINS server. Never set this parameter to yes on more than one machine within the same subnet. wins support = no ; Printer support printing = CUPS printcap name = CUPS ; Logs log file = /var/log/samba/log.%m syslog = 0 syslog only = no ; Configuring binding to which interfaces to listen on, if listens on all interfaces are not specified; interfaces = lo, eth0 ; bind interfaces only = true ; ; ; path = /var/lib/samba/printers ; browseable = yes ; guest ok = yes ; read only = yes ; write list = root ; create mask = 0664 ; directory mask = 0775 ; ; ; path = /tmp ; printable = yes ; guest ok = yes ; browseable = no ; ; ;path = /media/cdrom ;browseable = yes ;read only = yes ;guest ok = yes ; Hard drive ball; The name of the balls is visible from clients; Path to the shared disk path = /media/sda1 ; Is it possible to browse browseable = yes read only = no guest ok = no create mask = 0644 directory mask = 0755 ; Binding to a specific user name or group, names separated by a space; force user = user1 user2 ; force group = group1 group2 ; Another hard drive, similar to the one above path = /media/sde1 browseable = yes read only = no guest ok = no create mask = 0644 directory mask = 0755

Now we need to deal with the users.

Samba uses users that are already in the system, let’s take the name user as an example, let’s say that it is already in the system, we need to add it to the SMB database and assign a password to access shared resources, we’ll do this with the command:

Smbpasswd -a user

You will be prompted to enter a password, the user will be added to the database, now you need to enable this user.

Smbpasswd -e user

Next, let's create an alias for the username user to make it easier for us to access from a Windows machine on which we have, for example, a user named Admin. To do this, we'll create and edit the file /etc/samba/smbusers:

Sudo touch /etc/samba/smbusers sudo gedit /etc/samba/smbusers

Write a couple of lines into the file

# Unix_name = SMB_name1 SMB_name2 user = Admin

This completes the setup, restart Samba.

Samba file server for Windows network

Very often Samba is used to create a file server on a Windows network.

File server as part of an Active Directory domain

In order to create a file server integrated into an Active Directory domain, you will first need to join your Ubuntu machine to the domain. A separate article is devoted to this:

To create a file server, you do not need to configure PAM, just add domain users and groups via Winbind to the system.

After successfully logging into the domain, all you have to do is configure the shared resources on your computer.

Here you should immediately pay attention to one very important thing: Samba tries to map the rights to Windows files onto Unix rights, however, due to fundamental differences in the mechanisms for assigning rights, this is not always possible. Please note that file rights are always and in any case controlled by your file system on a computer running Ubuntu; Samba can only adapt to them, but not change their behavior.

Therefore, by default, shared resources will have very limited access control capabilities - assigning different rights to the user, group and everyone else. However, this can be easily fixed by adding POSIX ACL support to your FS. In this case, it will be possible to assign different rights to different users and groups, much like in Windows.

POSIX ACL support is available in at least ext3/4; to activate it, you just need to add the acl parameter to the mounting options of the desired partition.

It is important that the directory you want to share via Samba is on a disk mounted with the acl option. Otherwise, you will not be able to properly use the mechanism for delimiting access rights to files on the shares.

There is one more very important point: POSIX ACLs do not support inheritance of access rights from parent directories, but in Windows this feature is present. Therefore, Samba implements an additional mechanism for storing information about the inheritance of access rights, which uses extended file system attributes. Therefore, in order for Samba to correctly handle inheritance of rights other than acl, it is necessary to add the user_xattr parameter to the file system mounting options, which is responsible for enabling support for extended attributes.

For example, I always use separate LVM disks to organize shared resources, and my fstab lines for them look something like this:

/dev/mapper/data-profiles /var/data/profiles ext3 defaults,noexec,acl,user_xattr 0 2

The noexec option is needed because there should be 100% no Linux executable files on Windows shares, and it wouldn’t hurt to be on the safe side once again.

To work with acl on Ubuntu, you need to install a package of appropriate utilities:

Sudo aptitude install acl

Then you can view the extended rights (i.e. ACL) for a file or directory with the command

Getfacl file

And install with the command

Setfacl file

Just in case, I would like to draw your attention to the fact that the POSIX ACL mechanism has nothing to do with Samba - it is simply an add-on to the standard mechanism for dividing rights in Linux. Accordingly, Samba can use it, but cannot change or bypass it in any way.

To work with extended FS attributes, you will need a utility package very similar to acl - attr , which can be installed with the command

Sudo aptitude install attr

To view extended attributes you can use the command

Getfattr file

And for installation

Setfattr file

However, there is one small catch. The fact is that Samba stores all information about inheritance in binary form in a single extended attribute user.SAMBA_PAI. Therefore, you will not be able to change anything using setfattr, unless you completely remove extended attributes (sometimes this may need to be done).

Well, you will have to manage the inheritance of rights from a Windows machine using the standard tools of this system. Or using the smbcacls utility, if you figure out how to use it.

There is also an experimental VFS module acl_xattr, which allows you to store NT ACLs entirely in extended attributes. Unfortunately, there is no documentation on it, so it’s difficult to say anything intelligible about it. It is expected that Samba 4 will have full integrated support for NT ACLs, but for now you can use what is available.

If you have anything to add about extended attributes in Samba and methods of working with them, be sure to write to this topic on the forum. I would be grateful for any links, articles and comments on the topic.

In addition, extended file system attributes allow Samba to enable full support for DOS file attributes such as hidden, archive, etc.

So, let's assume that you have a directory on the system that you want to share via Samba (and it is located on a disk mounted with acl and user_xattr support). Now you need to actually configure its sharing. To do this, you need to enter the appropriate information into the /etc/samba/smb.conf file.

Let's start with the general settings that can be added to the section of this file (these are not all possible parameters, just a few quite useful ones):

# Disable printer sharing. Unless, of course, you really want to share them. # To completely disable you need to specify all 4 lines below load printers = no show add printer wizard = no printcap name = /dev/null disable spoolss = yes # Make files with the following names hidden when viewed on Windows hide files = /$RECYCLE .BIN/desktop.ini/lost+found/Thumbs.db/ # Use the next UNIX user as a public share as Guest guest account = nobody # Treat unregistered users as guests map to guest = Bad User ## Settings using advanced file system attributes # Handle inheritance of rights using extended FS attributes map acl inherit = yes # Use extended FS attributes to store DOS attributes store dos attributes = yes # Disable DOS attribute mapping on UNIX rights, enabled by default # According to man smb.conf when When using extended attributes, these options must be disabled map archive = no map system = no map hidden = no map readonly = no

Now the settings for the directly shared resource. I call it profiles, and physically on the Ubuntu machine it is located at /var/data/profiles:

# Comment comment = User Profiles # Path to the folder that we are sharing path = /var/data/profiles/ # Users with unlimited access rights to the share # I have a domain administrators group. # When working with files, these users are treated as local root admin users = "@DOMAIN\Domain Administrators" # Hide folders to which the user does not have access hide unreadable = yes # Non-read-only access read only = no # Masks for created files - can be set as desired #create mask = 0600 #directory mask = 0700 # Disabling locking - it is better to disable locking = no

There are many other options - it's worth consulting the Samba documentation for details.

Do not forget to set the correct owner and access rights to the folder that you are sharing, otherwise, despite any samba settings, writing to it may be prohibited at the Linux permission level. I usually do it like this:

Sudo chmod ug+rwx /var/data/profiles sudo chown root:"domain users" /var/data/profiles

Please note, since your Ubuntu machine is joined to a domain, you can use domain users and groups as file owners directly in Ubuntu.

Check that Samba configuration is correct with the command

Testparm

Then restart Samba:

Sudo /etc/init.d/samba restart

Now you can access the shared resource from any machine in the domain.

By the way, don't forget about SGID and Sticky bits for directories. They will allow you to inherit the owning group and prevent users from deleting files that are not theirs - this can be very convenient for multi-user storages. However, unlike editing rights from Windows, changing these bits on folders on a shared resource will not work - only manually directly on the Ubuntu computer.

Among other things, Samba allows you to organize the storage of previous versions of files, which is sometimes useful when creating shared resources with user data.

Standalone file server

Not everyone has an Active Directory domain. Therefore, there is often a need to organize an offline file storage on a Linux machine with its own authorization system. It's very easy to do.

The main feature of this organization of file storage will be that all information about users will be stored in the Samba database; accordingly, users will have to be added and deleted to Samba manually.

The most important thing is to decide on the method of accessing the resource. To change it, you must correctly set the value of the security parameter in the section of the /etc/samba/smb.conf file. You can read more about this parameter or in the official documentation.

Typically the value used is share or user .

Standalone file server without authorization

It is convenient for the house so that everyone can see everyone. This can be done by adding 4 lines to the section of the /etc/samba/smb.conf file. Some may already exist.

[global] workgroup = WORKGROUP map to guest = Bad User netbios name = NOTEBOOK security = user

NOTEBOOK - the name of the computer that will be on the network. In addition, you need to install additional programs:

sudo apt-get install samba

For kubuntu you also need to install smb4k. After editing the configs, you need to restart the services. In systemd (since 15.04) the restart looks like this:

sudo systemctl restart smbd.service nmbd.service

You can view the “balls” through the file browser nautilus, konkueror, or like this:

Smbclient -L 127.0.0.1

. Official documentation in English.

Sharing a folder on ubuntu

Create a folder for sharing files.

mkdir ~/share

Add the following lines to the end of the /etc/samba/smb.conf file, replacing yuraku1504 with the username of the computer running samba:

[ MyShareWork] comment = Anonymous Samba Share path = / home/ yuraku1504/ share guest ok = yes browsable =yes writable = yes read only = no force user = yuraku1504 force group = yuraku1504

The folder will be opened for reading and writing.

Or maybe it’s just interest and curiosity that push users to search for various suitable software. Samba is one such software. You need to know how to set up Samba on Ubuntu Server if you want to turn your computer into a database or file storage.

Installing Samba on Ubuntu Server allows you to create a database.

If you thought that the page was dedicated to learning dance, you were slightly mistaken. Samba is free software. It provides access to printers and files. And it does this on various operating systems.

What is it for?

In comparison with other software packages for similar purposes, Samba has several advantages and features.

  • Allows you to connect a Unix-like system, i.e., any Linux and Windows system, to each other. And not only Windows. The program is very “omnivorous”: MacOS, Solaris and other operating systems of varying degrees of popularity.
  • Samba allows Windows users to use Ubuntu computers as a server. That is, use the files to which access has been established, as well as some of the connected devices.
  • Supports the NT Domain domain structure, manages NT users, supports member and primary controller functions.

Probably, for many, the main thing from this is communication with Windows machines. In this case, they act as a client, and the Ubuntu computer acts as a server. On the other hand, an Ubuntu user can also access Windows network folders.

Samba has been produced since 1992. And, most importantly, new versions are still being released. The latter was released on March 7, 2017. Every year, developers try to establish compatibility with a large number of different versions of operating systems, but the main feature remains the connection of Linux systems with Microsoft. Compared to Windows Server, Samba may be inferior to it due to the lack of support for some protocols and host infrastructure. However, many argue that the speed of Samba is much higher.

Setting up Samba

Before setting up, the program must be installed. Installing Samba is done in the same way as with other programs - by entering the command into the terminal:

sudo apt-get install samba

Please note right away: all the steps that will be described, including installing the program, can be performed both on simple Ubuntu and on Ubuntu Server. Only the latter has an exclusively text interface available.

After installation, you should make a backup of the configuration file:

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

$ sudo vi /etc/samba/smb.conf

Or we edit an existing one. This file contains the basic settings of the Samba server. To figure out what we'll do next, we need to understand what the different lines mean.

  • Workgroup - working group. The value of this parameter will also often be Workgroup, since in Windows the default workgroup domain looks like this.
  • Netbios name is the name of the Ubuntu computer as seen by Windows users. Here you can enter the value at your discretion.
  • Security - user authorization mode. The default is User, that is, authentication at the user level. For now, it's best to leave it that way.
  • Os level - indicates the priority that Samba has over other clients (PCs) on the local or Internet network.
  • Name resolve order - order of IP address resolution by NetBIOS name.
  • Read only - privilege to read or write a directory. The value can be “yes” - read only, “no” - write.

Create a user

This is the simplest action with which you can start working with Samba.

Add a user in the OS itself:

$ useradd -M -l -s /sbin/nologin username

Let's create a password for it:

Let's add our user to the Samba database:

$ smbpasswd -a username

You can perform various other actions using the $ smbpasswd command:

  • $ smbpasswd username - change password
  • $ smbpasswd -x username - delete a user
  • $ smbpasswd -d username - ban user

The server must be rebooted if you make changes to the configuration file. This is done using the command:

$ systemctl restart smb

These are the basic Samba settings. Now you can try to put the program into practice.

Folder access

First, let's try to create a folder that will be accessible to all users, even those who are not authorized in Samba.

We create a folder with which we will then work on two computers:

$ sudo mkdir -p /samba/access

Now we give this folder extended access so that any client on our local network can open it:

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

The owner according to the code is nobody.

Now in the server configuration file you need to make two sections: the first one containing basic information:


workgroup = WORKGROUP
server string = Samba Server %v
netbios name = srvr1
security = user
map to guest = bad user
name resolve order = bcast host
dns proxy = no
#==============
And the second one, containing data about the access folder:

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

The sections follow one after another in the same order.

Update server changes:

$ sudo service smbd restart

Actions with a Windows computer

On Windows, you also need to perform some steps so that you can easily open a new shared folder and edit it.

  1. Open the command line. It is advisable to do this with extended rights, i.e. as an administrator.
  2. We execute the command:
  3. notepad C:\Windows\System32\drivers\etc\hosts
  4. A file opens in which we enter the following line:
  5. 168.0.1 srvr1.domain.com srvr1
    Thanks to it, the folder will become accessible.
  6. You can open it using the “Run” line. Press Win + R, enter: After this, a folder will open for us.

Closed folder

A configured Samba server can also be used to create network folders with limited access. Such a folder must also be created first and then added to the Samba configuration.

Let's make a folder called "Closed":

$ sudo mkdir -p /samba/allaccess/closed

Let's create a special group that can have access to this folder:

$ sudo addgroup securedgroup

We create special rights for different groups:

$ cd /samba/access
$ sudo chown -R richard:securedgroup closed
$ sudo chmod -R 0770 closed/

Just as in the case of an open folder, we add information to the configuration:


path = /samba/access/closed
valid users = @securegroup
guest ok = no
writable = yes
browsable = yes

We restart the server.

As you can understand, we created a Closed folder inside Access. Thus, Access can be opened by every user on the local network, but in order to view and edit Closed, you need to have special rights.

To make sure that everything works exactly as we specified in the batch file, you can follow a few simple steps.

We create a user and add him to our closed group:

$ sudo usermod -a -G securedgroup winston

Our user's name is like a pack of cigarettes (or the Prime Minister of Britain).

Let's create a password for Winston:

$ sudo smbpasswd -a winston

After this, we will be prompted to enter a new password to log in again under the newly created account. Don't forget to reboot after this. Now you know how to set up a server via Samba in Ubuntu.

Of course, Samba's capabilities are not limited to just creating simple folders. But these simple instructions and examples show what you can do with this program. This will be the first step towards understanding the essence of server PCs and their management.







2024 gtavrl.ru.