Samba file share linux

How to share files with Samba

Samba provides easy, flexible, cross-platform, and open source collaboration across your organization.

File system

Career advice

The Samba project provides file sharing and print services for computers on a network. It uses the Server Message Block and Common Internet File System (SMB/CIFS) protocol, so the services created by running Samba are available to Linux, macOS, and Windows clients. It’s an essential service to run in organizations that support multiple operating systems, and it’s even useful on homogenous networks.

It’s not difficult to set up, and all you need is at least one server you want to designate as a file-share host (it doesn’t have to be rack mounted and could even be a dedicated workstation). For client access, Samba is either built into the operating system or easily installed from a repository.

Install Samba

On your designated Samba server, install the Samba package:

This command also installs the samba-common-tools and samba-libs packages.

Next, start the SMB and NMB daemons. The SMB daemon manages most Samba services, while the NMB daemon provides NetBIOS services. Here are the commands:

$ systemctl enable --now smb $ systemctl enable --now nmb

That’s the installation. All that’s left is a little configuration.

Configure your firewall

Make sure that your file-share server is accessible over your network by adding the samba service to your firewall config:

$ sudo systemctl enable --now firewalld $ sudo firewall-cmd --list-services cockpit dhcpv6-client ssh $ sudo firewall-cmd --add-service samba success

Configure Samba

Create a directory on the server to hold your shared files and folders, and change the SELinux context to samba_share_t :

$ sudo mkdir /sambashare $ sudo chcon -t samba_share_t /sambashare/

To configure shares and users, edit the /etc/samba/smb.conf file. The default file has several good examples of common options, including provisions for shared printers and home directories.

Читайте также:  Фон для linux ubuntu

There’s a global section, which defines a workgroup. I arbitrarily set mine to SAMBA . I have no other existing workgroups on my network, so the workgroup hardly matters for my setup. If your organization has a specific workgroup structure, then follow that.

[global] workgroup = SAMBA security = user passdb backend = tdbsam . 

By default, your Samba server’s NetBIOS name is the server’s Linux hostname. If you don’t have DNS configured on your local network, you can use the server’s IP address when contacting the Samba server.

[ Download the Linux networking cheat sheet to get a list of Linux utilities and commands for managing servers and networks. ]

Create a shared location

To create a new share location, add a section to the /etc/samba/smb.conf configuration file with these two definitions:

[sambashare] path = /sambashare read only = No

Источник

How to create a Samba share

Samba allows for Windows and other clients to connect to file share directories on Linux hosts. It implements the server message block (SMB) protocol. This guide covers creating a shared file location on a Fedora machine that can be accessed by other computers on the local network.

Install and enable Samba

The following commands install Samba and set it to run via systemctl . This also sets the firewall to allow access to Samba from other computers.

sudo dnf install samba sudo systemctl enable smb --now firewall-cmd --get-active-zones sudo firewall-cmd --permanent --zone=FedoraWorkstation --add-service=samba sudo firewall-cmd --reload

Sharing a directory inside /home

In this example you will share a directory inside your home directory, accessible only by your user.

Samba does not use the operating system users for authentication, so your user account must be duplicated in Samba. So if your account is jane on the host, the user jane must also be added to Samba. While the usernames must match, the passwords can be different.

Читайте также:  Check linux system info

Create a user called jane in Samba:

Create a directory to be the share for jane, and set the correct SELinux context:

mkdir /home/jane/share sudo semanage fcontext --add --type "samba_share_t" "/home/jane/share(/.*)?" sudo restorecon -R ~/share

Samba configuration lives in the /etc/samba/smb.conf file. Adding the following section at the end of the file will instruct Samba to set up a share for jane called «share» at the /home/jane/share directory just created.

[share] comment = My Share path = /home/jane/share writeable = yes browseable = yes public = yes create mask = 0644 directory mask = 0755 write list = user

Restart Samba for the changes to take effect:

sudo systemctl restart smb

Sharing a directory for many users

In this example, you will share a directory (outside your home directory) and create a group of users with the ability to read and write to the share.

Remember that a Samba user must also be a system user, in order to respect filesystem permissions. This example creates a system group myfamily for two new users jack and maria .

sudo groupadd myfamily sudo useradd -G myfamily jack sudo useradd -G myfamily maria

You could create these users without a system password. This would prevent access to the system via SSH or local login.

Add jack and maria to Samba and create their passwords:

sudo smbpasswd -a jack sudo smbpasswd -a maria

Setting up the shared folder:

sudo mkdir /home/share sudo chgrp myfamily /home/share sudo chmod 770 /home/share sudo semanage fcontext --add --type "samba_share_t" "/home/share(/.*)?" sudo restorecon -R /home/share

Each share is described by its own section in the /etc/samba/smb.conf file. Add this section to the bottom of the file:

[family] comment = Family Share path = /home/share writeable = yes browseable = yes public = yes valid users = @myfamily create mask = 0660 directory mask = 0770 force group = +myfamily
  • valid users : only users of the group family have access rights. The @ denotes a group name.
  • force group = +myfamily : files and directories are created with this group, instead of the user group.
  • create mask = 0660 : files in the share are created with permissions to allow all group users to read and write files created by other users.
  • directory mask = 0770 : as before, but for directories.
Читайте также:  Linux chown все файлы

Restart Samba for the changes to take effect:

sudo systemctl restart smb

Источник

Оцените статью
Adblock
detector